Skip to content

Commit eeb0dd3

Browse files
Mpdreamzclaude
andauthored
Retry S3 link registry fetch on transient errors in match command (#3229)
Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 914d54b commit eeb0dd3

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryBuildMatchingService.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Elastic.Documentation.Configuration.Assembler;
99
using Elastic.Documentation.Diagnostics;
1010
using Elastic.Documentation.LinkIndex;
11+
using Elastic.Documentation.Links;
1112
using Elastic.Documentation.Services;
1213
using Microsoft.Extensions.Logging;
1314
using Nullean.ScopedFileSystem;
@@ -24,6 +25,26 @@ ScopedFileSystem fileSystem
2425
{
2526
private readonly ILogger _logger = logFactory.CreateLogger<RepositoryBuildMatchingService>();
2627

28+
private async Task<LinkRegistry> GetRegistryWithRetry(Aws3LinkIndexReader provider, Cancel ctx)
29+
{
30+
const int maxAttempts = 3;
31+
for (var attempt = 1; attempt <= maxAttempts; attempt++)
32+
{
33+
try
34+
{
35+
return await provider.GetRegistry(ctx);
36+
}
37+
catch (Exception ex) when (attempt < maxAttempts)
38+
{
39+
var delay = TimeSpan.FromSeconds(Math.Pow(2, attempt));
40+
_logger.LogWarning("S3 link registry fetch failed (attempt {Attempt}/{Max}), retrying in {Delay}s: {Message}",
41+
attempt, maxAttempts, delay.TotalSeconds, ex.Message);
42+
await Task.Delay(delay, ctx);
43+
}
44+
}
45+
return await provider.GetRegistry(ctx);
46+
}
47+
2748
//TODO return contentsourcematch
2849
/// <summary>
2950
/// Validates whether the <paramref name="branchOrTag"/> on <paramref name="repository"/> should be build and therefor published.
@@ -43,7 +64,7 @@ public async Task<bool> ShouldBuild(IDiagnosticsCollector collector, string? rep
4364

4465
// environment does not matter to check the configuration, defaulting to dev
4566
var linkIndexProvider = Aws3LinkIndexReader.CreateAnonymous();
46-
var linkRegistry = await linkIndexProvider.GetRegistry(ctx);
67+
var linkRegistry = await GetRegistryWithRetry(linkIndexProvider, ctx);
4768
var alreadyPublishing = linkRegistry.Repositories.ContainsKey(repo);
4869
_logger.LogInformation("'{Repository}' publishing to link registry: {PublishState} ", repo, alreadyPublishing);
4970
var assembleContext = new AssembleContext(configuration, configurationContext, "dev", collector, fileSystem, fileSystem, null, null);

0 commit comments

Comments
 (0)