code4me / 4me-sdk-graphql-dotnet

.NET SDK for 4me GraphQL, see https://developer.4me.com/graphql/
MIT License
3 stars 1 forks source link

Bulk Import should accept a CancellationToken #11

Closed TheToor closed 1 week ago

TheToor commented 1 month ago

Imports may take a long time. I want the ability to have it timeout after it takes to long. I think the easiest way would be for the AwaitImport/Export Methods to accept a cancellation token to stop the polling. And/or alternative would be a timeout parameter for the method to time out and return an TimeoutException.

klaasvandeweerdt commented 1 month ago

@TheToor, you can currently use Task<BulkExportResponse> GetExportStatus(string token) and Task<BulkImportResponse> GetImportStatus(string token) to build your own methods as they return the current state of the import or export.

klaasvandeweerdt commented 1 month ago

I went for the "And alternative", the AwaitImport/Export have been updated, supporting both.

Task<Stream> AwaitDownload(string token, int pollingIntervalInSeconds)
Task<Stream> AwaitDownload(string token, int pollingIntervalInSeconds, CancellationToken cancellationToken)
Task<Stream> AwaitDownload(string token, int pollingIntervalInSeconds, int timeoutInSeconds)

Task AwaitDownloadAndSave(string token, int pollingIntervalInSeconds, string path)
Task AwaitDownloadAndSave(string token, int pollingIntervalInSeconds, string path, CancellationToken cancellationToken)
Task AwaitDownloadAndSave(string token, int pollingIntervalInSeconds, string path, int timeoutInSeconds)

Task<BulkImportResponse> AwaitImport(string token, int pollingIntervalInSeconds)
Task<BulkImportResponse> AwaitImport(string token, int pollingIntervalInSeconds, CancellationToken cancellationToken)
Task<BulkImportResponse> AwaitImport(string token, int pollingIntervalInSeconds, int timeoutInSeconds)
TheToor commented 1 month ago

Perfect :) Maybe you can change the int to TimeSpan instead do more adhere to current standards? Having a cancellation token for potentially long running operations is just good design I think. No matter if we can build our own methods. But to be fair I didn't check that I can build my own loop :)

klaasvandeweerdt commented 1 month ago

Agree with the TimeSpan, I will update the code later this week and replace int timeoutInSeconds with a TimeSpan timeout.

klaasvandeweerdt commented 1 month ago

@TheToor, thanks for the feedback, I have updated to code, changed int timeoutInSeconds to TimeSpan timeout.

klaasvandeweerdt commented 1 week ago

Closing this enhancement as this was implemented and released two week ago.