@@ -66,6 +66,7 @@ pub fn retry<I, E>(operation_name: impl ToString, logger: &Logger) -> RetryConfi
6666 redact_log_urls : false ,
6767 phantom_item : PhantomData ,
6868 phantom_error : PhantomData ,
69+ max_delay : RETRY_DEFAULT_LIMIT ,
6970 }
7071}
7172
@@ -79,6 +80,7 @@ pub struct RetryConfig<I, E> {
7980 phantom_item : PhantomData < I > ,
8081 phantom_error : PhantomData < E > ,
8182 redact_log_urls : bool ,
83+ max_delay : Duration ,
8284}
8385
8486impl < I , E > RetryConfig < I , E >
@@ -159,6 +161,12 @@ where
159161 pub fn no_timeout ( self ) -> RetryConfigNoTimeout < I , E > {
160162 RetryConfigNoTimeout { inner : self }
161163 }
164+
165+ /// Set the maximum delay between retries.
166+ pub fn max_delay ( mut self , max_delay : Duration ) -> Self {
167+ self . max_delay = max_delay;
168+ self
169+ }
162170}
163171
164172pub struct RetryConfigWithTimeout < I , E > {
@@ -184,6 +192,7 @@ where
184192 let warn_after = self . inner . warn_after ;
185193 let limit_opt = self . inner . limit . unwrap ( & operation_name, "limit" ) ;
186194 let redact_log_urls = self . inner . redact_log_urls ;
195+ let max_delay = self . inner . max_delay ;
187196 let timeout = self . timeout ;
188197
189198 trace ! ( logger, "Run with retry: {}" , operation_name) ;
@@ -196,6 +205,7 @@ where
196205 warn_after,
197206 limit_opt,
198207 redact_log_urls,
208+ max_delay,
199209 move || {
200210 try_it ( )
201211 . timeout ( timeout)
@@ -227,6 +237,7 @@ impl<I, E> RetryConfigNoTimeout<I, E> {
227237 let warn_after = self . inner . warn_after ;
228238 let limit_opt = self . inner . limit . unwrap ( & operation_name, "limit" ) ;
229239 let redact_log_urls = self . inner . redact_log_urls ;
240+ let max_delay = self . inner . max_delay ;
230241
231242 trace ! ( logger, "Run with retry: {}" , operation_name) ;
232243
@@ -238,6 +249,7 @@ impl<I, E> RetryConfigNoTimeout<I, E> {
238249 warn_after,
239250 limit_opt,
240251 redact_log_urls,
252+ max_delay,
241253 // No timeout, so all errors are inner errors
242254 move || try_it ( ) . map_err ( TimeoutError :: Inner ) ,
243255 )
@@ -280,6 +292,7 @@ fn run_retry<O, E, F, R>(
280292 warn_after : u64 ,
281293 limit_opt : Option < usize > ,
282294 redact_log_urls : bool ,
295+ max_delay : Duration ,
283296 mut try_it_with_timeout : F ,
284297) -> impl Future < Output = Result < O , TimeoutError < E > > > + Send
285298where
@@ -292,7 +305,7 @@ where
292305
293306 let mut attempt_count = 0 ;
294307
295- Retry :: spawn ( retry_strategy ( limit_opt, RETRY_DEFAULT_LIMIT ) , move || {
308+ Retry :: spawn ( retry_strategy ( limit_opt, max_delay ) , move || {
296309 let operation_name = operation_name. clone ( ) ;
297310 let logger = logger. clone ( ) ;
298311 let condition = condition. clone ( ) ;
0 commit comments