@@ -75,7 +75,7 @@ internal sealed class Registry
75
75
private const string DockerHubRegistry2 = "registry.hub.docker.com" ;
76
76
private static readonly int s_defaultChunkSizeBytes = 1024 * 64 ;
77
77
private const int MaxDownloadRetries = 5 ;
78
- private const int FixedDownloadDelayInSeconds = 1 ;
78
+ private readonly Func < TimeSpan > _retryDelayProvider ;
79
79
80
80
private readonly ILogger _logger ;
81
81
private readonly IRegistryAPI _registryAPI ;
@@ -88,7 +88,7 @@ internal sealed class Registry
88
88
/// </summary>
89
89
public string RegistryName { get ; }
90
90
91
- internal Registry ( string registryName , ILogger logger , IRegistryAPI registryAPI , RegistrySettings ? settings = null ) :
91
+ internal Registry ( string registryName , ILogger logger , IRegistryAPI registryAPI , RegistrySettings ? settings = null , Func < TimeSpan > ? retryDelayProvider = null ) :
92
92
this ( new Uri ( $ "https://{ registryName } ") , logger , registryAPI , settings )
93
93
{ }
94
94
@@ -97,15 +97,15 @@ internal Registry(string registryName, ILogger logger, RegistryMode mode, Regist
97
97
{ }
98
98
99
99
100
- internal Registry ( Uri baseUri , ILogger logger , IRegistryAPI registryAPI , RegistrySettings ? settings = null ) :
100
+ internal Registry ( Uri baseUri , ILogger logger , IRegistryAPI registryAPI , RegistrySettings ? settings = null , Func < TimeSpan > ? retryDelayProvider = null ) :
101
101
this ( baseUri , logger , new RegistryApiFactory ( registryAPI ) , settings )
102
102
{ }
103
103
104
104
internal Registry ( Uri baseUri , ILogger logger , RegistryMode mode , RegistrySettings ? settings = null ) :
105
105
this ( baseUri , logger , new RegistryApiFactory ( mode ) , settings )
106
106
{ }
107
107
108
- private Registry ( Uri baseUri , ILogger logger , RegistryApiFactory factory , RegistrySettings ? settings = null )
108
+ private Registry ( Uri baseUri , ILogger logger , RegistryApiFactory factory , RegistrySettings ? settings = null , Func < TimeSpan > ? retryDelayProvider = null )
109
109
{
110
110
RegistryName = DeriveRegistryName ( baseUri ) ;
111
111
@@ -119,6 +119,8 @@ private Registry(Uri baseUri, ILogger logger, RegistryApiFactory factory, Regist
119
119
_logger = logger ;
120
120
_settings = settings ?? new RegistrySettings ( RegistryName ) ;
121
121
_registryAPI = factory . Create ( RegistryName , BaseUri , logger , _settings . IsInsecure ) ;
122
+
123
+ _retryDelayProvider = retryDelayProvider ?? ( ( ) => TimeSpan . FromSeconds ( 1 ) ) ;
122
124
}
123
125
124
126
private static string DeriveRegistryName ( Uri baseUri )
@@ -439,7 +441,7 @@ public async Task<string> DownloadBlobAsync(string repository, Descriptor descri
439
441
_logger . LogTrace ( "Download attempt {0}/{1} for repository '{2}' failed. Error: {3}" , retryCount , MaxDownloadRetries , repository , ex . ToString ( ) ) ;
440
442
441
443
// Wait before retrying
442
- await Task . Delay ( TimeSpan . FromSeconds ( FixedDownloadDelayInSeconds ) , cancellationToken ) . ConfigureAwait ( false ) ;
444
+ await Task . Delay ( _retryDelayProvider ( ) , cancellationToken ) . ConfigureAwait ( false ) ;
443
445
}
444
446
}
445
447
0 commit comments