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 4 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 @@ -16,7 +16,7 @@ public interface IStorageClient
Task<IEnumerable<IFileMetadata>> UploadAsync(IEnumerable<string> filePaths, CancellationToken cancellationToken);

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);
CancellationToken cancellationToken, int batchSize = 20);

JArray Serialize(IEnumerable<IFileMetadata> filesMetadata);
}
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
35 changes: 21 additions & 14 deletions IndicoV2/Storage/StorageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<Stream> GetAsync(Uri uri, CancellationToken cancellationToken)

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

return DeserializeMetadata(metadata);
}
Expand All @@ -63,25 +63,32 @@ public JArray Serialize(IEnumerable<IFileMetadata> filesMetadata)

public async Task<(string Name, string Meta)> UploadAsync(Stream content,
string filePath,
CancellationToken cancellationToken) =>
(await UploadAsync(new[] {(filePath, content)}, cancellationToken)).SingleOrDefault();
CancellationToken cancellationToken, int batchSize = 20) =>
(await UploadAsync(new[] { (filePath, content) }, cancellationToken, batchSize)).SingleOrDefault();

public async Task<(string Name, string Meta)[]> UploadAsync(IEnumerable<(string Path, Stream Content)> files,
CancellationToken cancellationToken)
CancellationToken cancellationToken, int batchSize = 20)
{
var content = await CreateRequest(files, cancellationToken);
var response = await _indicoClient.HttpClient.PostAsync(UploadUri, content, cancellationToken);

using (var reader = new JsonTextReader(new StreamReader(await response.Content.ReadAsStreamAsync())))
var results = new (string Name, string Meta)[] { };
goatrocks marked this conversation as resolved.
Show resolved Hide resolved
var batches = files.Chunk(batchSize);
foreach (var batch in batches)
{
var uploadResult = await JArray.LoadAsync(reader, cancellationToken);
var content = await CreateRequest(files, cancellationToken);
var response = await _indicoClient.HttpClient.PostAsync(UploadUri, content, cancellationToken);

return uploadResult
.Select(t => (
Name: t.Value<string>("name"),
Meta: t.ToString()))
.ToArray();
using (var reader = new JsonTextReader(new StreamReader(await response.Content.ReadAsStreamAsync())))
{
var uploadResult = await JArray.LoadAsync(reader, cancellationToken);

var result = uploadResult
.Select(t => (
Name: t.Value<string>("name"),
Meta: t.ToString()))
.ToArray();
results = results.Concat(result).ToArray();
}
}
return results;
}

private async Task<HttpContent> CreateRequest(IEnumerable<(string Path, Stream Content)> files, CancellationToken cancellationToken)
Expand Down
1 change: 1 addition & 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
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