Skip to content

Commit

Permalink
add argument exception for invalid batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathanael Shim authored and Nathanael Shim committed Mar 11, 2024
1 parent 99ec729 commit d281349
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions IndicoV2.Abstractions/Submissions/ISubmissionsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface ISubmissionsClient
/// <param name="resultsFileVersion">Optional. Specifies version to use for the results file.</param>
/// <param name="bundle">Optional. Flag to batch all files under a single submission id.</param>
/// <returns><c><see cref="IEnumerable{T}">IEnumerable</see></c> of submissions ids.</returns>
Task<IEnumerable<int>> CreateAsync(int workflowId, IEnumerable<(string Name, Stream Content)> files, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false);
Task<IEnumerable<int>> CreateAsync(int workflowId, IEnumerable<(string Name, Stream Content)> files, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false, int batchSize = 20);

/// <summary>
/// Method creates <c><see cref="ISubmission"/></c>.
Expand All @@ -56,7 +56,7 @@ public interface ISubmissionsClient
/// <param name="resultsFileVersion">Optional. Specifies version to use for the results file.</param>
/// <param name="bundle">Optional. Flag to batch all files under a single submission id.</param>
/// <returns><c><see cref="IEnumerable{T}"/></c> of submissions ids.</returns>
Task<IEnumerable<int>> CreateAsync(int workflowId, IEnumerable<string> paths, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false);
Task<IEnumerable<int>> CreateAsync(int workflowId, IEnumerable<string> paths, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false, int batchSize = 20);

/// <summary>
/// Method lists <c><see cref="ISubmission"/></c>.
Expand Down
4 changes: 4 additions & 0 deletions IndicoV2/Storage/StorageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public JArray Serialize(IEnumerable<IFileMetadata> 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)
Expand Down
8 changes: 4 additions & 4 deletions IndicoV2/Submissions/SubmissionsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public async Task<IEnumerable<int>> CreateAsync(int workflowId, IEnumerable<Stre
return await _strawberryShakeClient.Submissions().Create(workflowId, (IEnumerable<(string Name, string Meta)>)files, cancellationToken, (SubmissionResultVersion?) resultsFileVersion, bundle);
}

public async Task<IEnumerable<int>> CreateAsync(int workflowId, IEnumerable<(string Name, Stream Content)> filesToUpload, CancellationToken cancellationToken = default, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false)
public async Task<IEnumerable<int>> 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);
}

Expand All @@ -68,7 +68,7 @@ public async Task<IEnumerable<int>> CreateAsync(int workflowId, IEnumerable<Uri>
await _strawberryShakeClient.Submissions().CreateUri(workflowId, uris, cancellationToken);

public async Task<IEnumerable<int>> CreateAsync(int workflowId, IEnumerable<string> 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)
Expand All @@ -84,7 +84,7 @@ public async Task<IEnumerable<int>> CreateAsync(int workflowId, IEnumerable<stri
}

}
return await CreateAsync(workflowId, filesToUpload: filesToUpload, cancellationToken, resultsFileVersion, bundle);
return await CreateAsync(workflowId, filesToUpload: filesToUpload, cancellationToken, resultsFileVersion, bundle, batchSize);
}

[Obsolete("This is the Legacy version and will be deprecated. Please use ListAsync instead.")]
Expand Down

0 comments on commit d281349

Please sign in to comment.