From d28134902b89f2f2c18997b9eb5e6185a0a07e3a Mon Sep 17 00:00:00 2001 From: Nathanael Shim Date: Mon, 11 Mar 2024 09:15:34 -0700 Subject: [PATCH] add argument exception for invalid batch size --- IndicoV2.Abstractions/Submissions/ISubmissionsClient.cs | 4 ++-- IndicoV2/Storage/StorageClient.cs | 4 ++++ IndicoV2/Submissions/SubmissionsClient.cs | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/IndicoV2.Abstractions/Submissions/ISubmissionsClient.cs b/IndicoV2.Abstractions/Submissions/ISubmissionsClient.cs index 667cc5e..fbb8610 100644 --- a/IndicoV2.Abstractions/Submissions/ISubmissionsClient.cs +++ b/IndicoV2.Abstractions/Submissions/ISubmissionsClient.cs @@ -34,7 +34,7 @@ public interface ISubmissionsClient /// Optional. Specifies version to use for the results file. /// Optional. Flag to batch all files under a single submission id. /// IEnumerable of submissions ids. - Task> CreateAsync(int workflowId, IEnumerable<(string Name, Stream Content)> files, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false); + Task> CreateAsync(int workflowId, IEnumerable<(string Name, Stream Content)> files, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false, int batchSize = 20); /// /// Method creates . @@ -56,7 +56,7 @@ public interface ISubmissionsClient /// Optional. Specifies version to use for the results file. /// Optional. Flag to batch all files under a single submission id. /// of submissions ids. - Task> CreateAsync(int workflowId, IEnumerable paths, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false); + Task> CreateAsync(int workflowId, IEnumerable paths, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false, int batchSize = 20); /// /// Method lists . diff --git a/IndicoV2/Storage/StorageClient.cs b/IndicoV2/Storage/StorageClient.cs index 7992430..5cb0e8e 100644 --- a/IndicoV2/Storage/StorageClient.cs +++ b/IndicoV2/Storage/StorageClient.cs @@ -69,6 +69,10 @@ public JArray Serialize(IEnumerable filesMetadata) public async Task<(string Name, string Meta)[]> UploadAsync(IEnumerable<(string Path, Stream Content)> files, CancellationToken cancellationToken, int batchSize = 20) { + if (batchSize <= 0) + { + throw new ArgumentException("Batch size must be greater than 0."); + } var results = new (string Name, string Meta)[] { }; var batches = files.Chunk(batchSize); foreach (var batch in batches) diff --git a/IndicoV2/Submissions/SubmissionsClient.cs b/IndicoV2/Submissions/SubmissionsClient.cs index a878469..7a2fbba 100644 --- a/IndicoV2/Submissions/SubmissionsClient.cs +++ b/IndicoV2/Submissions/SubmissionsClient.cs @@ -51,9 +51,9 @@ public async Task> CreateAsync(int workflowId, IEnumerable)files, cancellationToken, (SubmissionResultVersion?) resultsFileVersion, bundle); } - public async Task> CreateAsync(int workflowId, IEnumerable<(string Name, Stream Content)> filesToUpload, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false) + public async Task> CreateAsync(int workflowId, IEnumerable<(string Name, Stream Content)> filesToUpload, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false, int batchSize = 20) { - var filesUploaded = await _indicoClient.Storage().UploadAsync(filesToUpload, cancellationToken); + var filesUploaded = await _indicoClient.Storage().UploadAsync(filesToUpload, cancellationToken, batchSize: batchSize); return await _strawberryShakeClient.Submissions().Create(workflowId, filesUploaded, cancellationToken, (SubmissionResultVersion?)resultsFileVersion, bundle); } @@ -68,7 +68,7 @@ public async Task> CreateAsync(int workflowId, IEnumerable await _strawberryShakeClient.Submissions().CreateUri(workflowId, uris, cancellationToken); public async Task> CreateAsync(int workflowId, IEnumerable paths, - CancellationToken cancellationToken, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false) + CancellationToken cancellationToken, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false, int batchSize = 20) { var filesToUpload = new List<(string Name, Stream content)>(); foreach (var path in paths) @@ -84,7 +84,7 @@ public async Task> CreateAsync(int workflowId, IEnumerable