mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #1379 from wabbajack-tools/retry_authored_files_uploads
Retry all authored file uploads
This commit is contained in:
commit
d0b5b8448f
@ -80,12 +80,13 @@ namespace Wabbajack.Lib.AuthorApi
|
|||||||
{
|
{
|
||||||
var definition = await GenerateFileDefinition(queue, path, progressFn);
|
var definition = await GenerateFileDefinition(queue, path, progressFn);
|
||||||
|
|
||||||
using (var result = await _client.PutAsync($"{Consts.WabbajackBuildServerUri}authored_files/create",
|
await CircuitBreaker.WithAutoRetryAllAsync(async () =>
|
||||||
new StringContent(definition.ToJson())))
|
|
||||||
{
|
{
|
||||||
|
using var result = await _client.PutAsync($"{Consts.WabbajackBuildServerUri}authored_files/create",
|
||||||
|
new StringContent(definition.ToJson()));
|
||||||
progressFn("Starting upload", Percent.Zero);
|
progressFn("Starting upload", Percent.Zero);
|
||||||
definition.ServerAssignedUniqueId = await result.Content.ReadAsStringAsync();
|
definition.ServerAssignedUniqueId = await result.Content.ReadAsStringAsync();
|
||||||
}
|
});
|
||||||
|
|
||||||
var results = await definition.Parts.PMap(queue, async part =>
|
var results = await definition.Parts.PMap(queue, async part =>
|
||||||
{
|
{
|
||||||
@ -96,41 +97,29 @@ namespace Wabbajack.Lib.AuthorApi
|
|||||||
fs.Position = part.Offset;
|
fs.Position = part.Offset;
|
||||||
await fs.ReadAsync(buffer);
|
await fs.ReadAsync(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int retries = 0;
|
return await CircuitBreaker.WithAutoRetryAllAsync(async () =>
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
using var putResult = await _client.PutAsync(
|
||||||
{
|
$"{Consts.WabbajackBuildServerUri}authored_files/{definition.ServerAssignedUniqueId}/part/{part.Index}",
|
||||||
using var putResult = await _client.PutAsync(
|
new ByteArrayContent(buffer));
|
||||||
$"{Consts.WabbajackBuildServerUri}authored_files/{definition.ServerAssignedUniqueId}/part/{part.Index}",
|
var hash = Hash.FromBase64(await putResult.Content.ReadAsStringAsync());
|
||||||
new ByteArrayContent(buffer));
|
if (hash != part.Hash)
|
||||||
var hash = Hash.FromBase64(await putResult.Content.ReadAsStringAsync());
|
throw new InvalidDataException("Hashes don't match");
|
||||||
if (hash != part.Hash)
|
return hash;
|
||||||
throw new InvalidDataException("Hashes don't match");
|
});
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Utils.Log("Failure uploading part");
|
|
||||||
Utils.Log(ex.ToString());
|
|
||||||
if (retries <= 4)
|
|
||||||
{
|
|
||||||
retries++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Utils.ErrorThrow(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
progressFn("Finalizing upload", Percent.Zero);
|
progressFn("Finalizing upload", Percent.Zero);
|
||||||
using (var result = await _client.PutAsync($"{Consts.WabbajackBuildServerUri}authored_files/{definition.ServerAssignedUniqueId}/finish",
|
return await CircuitBreaker.WithAutoRetryAllAsync(async () =>
|
||||||
new StringContent(definition.ToJson())))
|
|
||||||
{
|
{
|
||||||
|
using var result = await _client.PutAsync(
|
||||||
|
$"{Consts.WabbajackBuildServerUri}authored_files/{definition.ServerAssignedUniqueId}/finish",
|
||||||
|
new StringContent(definition.ToJson()));
|
||||||
progressFn("Finished", Percent.One);
|
progressFn("Finished", Percent.One);
|
||||||
return new Uri(await result.Content.ReadAsStringAsync());
|
return new Uri(await result.Content.ReadAsStringAsync());
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user