Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV-11443] Use Batch Upload for workflow submission call #142

Merged
merged 6 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/AddDataSetFiles/AddDataSetFiles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion IndicoV2.Abstractions/IndicoV2.Abstractions.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
goatrocks marked this conversation as resolved.
Show resolved Hide resolved
<RootNamespace>IndicoV2</RootNamespace>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion IndicoV2.Abstractions/Storage/IStorageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IStorageClient
Task<Stream> GetAsync(Uri uri, CancellationToken cancellationToken);

[Obsolete("On this level it's preferable to use streams instead of paths")]
Task<IEnumerable<IFileMetadata>> UploadAsync(IEnumerable<string> filePaths, CancellationToken cancellationToken);
Task<IEnumerable<IFileMetadata>> UploadAsync(IEnumerable<string> filePaths, CancellationToken cancellationToken, int batchSize);
nateshim-indico marked this conversation as resolved.
Show resolved Hide resolved

Task<(string Name, string Meta)[]> UploadAsync(IEnumerable<(string Path, Stream Content)> files,
nateshim-indico marked this conversation as resolved.
Show resolved Hide resolved
CancellationToken cancellationToken);
Expand Down
2 changes: 1 addition & 1 deletion IndicoV2.IntegrationTests/Storage/StorageClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task UploadAsync_ShouldReturnUploadedFileInfo()
var filePath = _dataHelper.Files().GetSampleFilePath();

// Act
var uploadedFiles = (await _storageClient.UploadAsync(new[] {filePath}, default)).ToArray();
var uploadedFiles = (await _storageClient.UploadAsync(new[] {filePath}, default, batchSize: 20)).ToArray();

// Assert
uploadedFiles.Should().HaveCount(1);
Expand Down
2 changes: 1 addition & 1 deletion IndicoV2/DataSets/DataSetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<IEnumerable<IDataSetFull>> ListFullAsync(int? limit = null, Ca
public async Task<IDataSetAddFilesResult> AddFilesAsync(int dataSetId, IEnumerable<string> filePaths,
CancellationToken cancellationToken)
{
var uploadedFiles = await _storage.UploadAsync(filePaths, cancellationToken);
var uploadedFiles = await _storage.UploadAsync(filePaths, cancellationToken, batchSize: 20);
var metadata = _storage.Serialize(uploadedFiles);
var result = await _dataSetSsClient.AddFiles(dataSetId, metadata.ToString(), cancellationToken);

Expand Down
2 changes: 1 addition & 1 deletion IndicoV2/IndicoV2.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<BuildType>V2</BuildType>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions IndicoV2/Storage/StorageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public async Task<Stream> GetAsync(Uri uri, CancellationToken cancellationToken)
return result;
}

public async Task<IEnumerable<IFileMetadata>> UploadAsync(IEnumerable<string> filePaths, CancellationToken cancellationToken)
public async Task<IEnumerable<IFileMetadata>> UploadAsync(IEnumerable<string> filePaths, CancellationToken cancellationToken, int batchSize = 20)
{
var metadata = await new UploadFile(_indicoClient) {Files = filePaths.ToList()}.Call(cancellationToken);
var metadata = await new UploadFile(_indicoClient) {Files = filePaths.ToList()}.CallBatched(batchSize, cancellationToken);

return DeserializeMetadata(metadata);
}
Expand Down
13 changes: 13 additions & 0 deletions IndicoV2/Storage/UploadFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System;
using IndicoV2.Exception;
using System.Linq;

namespace IndicoV2.Storage
{
Expand Down Expand Up @@ -93,5 +94,17 @@ public async Task<JArray> Call(CancellationToken cancellationToken = default)

return uploadResult;
}

public async Task<JArray> CallBatched(int batchSize, CancellationToken cancellationToken = default)
{
var results = new JArray();
var batches = Files.Chunk(batchSize);
foreach (var batch in batches)
{
var result = await new UploadFile(_client) {Files = batch.ToList()}.Call(cancellationToken);
results.Merge(result);
}
return results;
}
}
}
1 change: 1 addition & 0 deletions IndicoV2/Storage/UploadStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public async Task<JArray> Call(CancellationToken cancellationToken = default)

return uploadResult;
}

}
}

Loading