88using Elastic . Documentation . Configuration . Assembler ;
99using Elastic . Documentation . Diagnostics ;
1010using Elastic . Documentation . LinkIndex ;
11+ using Elastic . Documentation . Links ;
1112using Elastic . Documentation . Services ;
1213using Microsoft . Extensions . Logging ;
1314using 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