Skip to content
Open
Changes from 1 commit
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
41 changes: 31 additions & 10 deletions src/AzurePipelines/PipelineCachingCacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,22 @@ protected override async Task AddNodeAsync(
result.ProofNodes,
ContentFormatConstants.Files);

CreateResult createResult = await WithHttpRetries(
() => _cacheClient.CreatePipelineCacheArtifactAsync(entry, null, cancellationToken),
await WithHttpRetries(
async () =>
{
try
{
CreateResult createResult = await _cacheClient.CreatePipelineCacheArtifactAsync(entry, null, cancellationToken);
Tracer.Debug(context, $"Cache entry for {fingerprint} stored in scope `{createResult.ScopeUsed}`");
}
catch (PipelineCacheItemAlreadyExistsException)
{
Tracer.Debug(context, $"Cache entry for {fingerprint} already exists.");
}
},
cacheContext: context,
message: $"Storing cache key for {fingerprint}",
cancellationToken);
Tracer.Debug(context, $"Cache entry stored in scope `{createResult.ScopeUsed}`");
}
finally
{
Expand Down Expand Up @@ -730,16 +740,27 @@ private string ComputeSelectorsKey(BuildXL.Cache.MemoizationStore.Interfaces.Ses
cancellationToken);
}

private Task WithHttpRetries(Func<Task> taskFactory, Context cacheContext, string message, CancellationToken token)
=> WithHttpRetries(
async () =>
{
await taskFactory();
return 0; // we don't care about the result, just that it succeeded
},
cacheContext,
message,
token);

private Task<T> WithHttpRetries<T>(Func<Task<T>> taskFactory, Context cacheContext, string message, CancellationToken token)
{
return AsyncHttpRetryHelper<T>.InvokeAsync(
taskFactory,
maxRetries: 10,
tracer: _azureDevopsTracer,
canRetryDelegate: _ => true, // retry on any exception
cancellationToken: token,
continueOnCapturedContext: false,
context: EmbedCacheContext(cacheContext, message));
taskFactory,
maxRetries: 10,
tracer: _azureDevopsTracer,
canRetryDelegate: _ => true, // retry on any exception
cancellationToken: token,
continueOnCapturedContext: false,
context: EmbedCacheContext(cacheContext, message));
}

public override async ValueTask DisposeAsync()
Expand Down
Loading