@@ -66,6 +66,7 @@ pub fn retry<I, E>(operation_name: impl ToString, logger: &Logger) -> RetryConfi
66
66
redact_log_urls : false ,
67
67
phantom_item : PhantomData ,
68
68
phantom_error : PhantomData ,
69
+ max_delay : RETRY_DEFAULT_LIMIT ,
69
70
}
70
71
}
71
72
@@ -79,6 +80,7 @@ pub struct RetryConfig<I, E> {
79
80
phantom_item : PhantomData < I > ,
80
81
phantom_error : PhantomData < E > ,
81
82
redact_log_urls : bool ,
83
+ max_delay : Duration ,
82
84
}
83
85
84
86
impl < I , E > RetryConfig < I , E >
@@ -159,6 +161,12 @@ where
159
161
pub fn no_timeout ( self ) -> RetryConfigNoTimeout < I , E > {
160
162
RetryConfigNoTimeout { inner : self }
161
163
}
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
+ }
162
170
}
163
171
164
172
pub struct RetryConfigWithTimeout < I , E > {
@@ -184,6 +192,7 @@ where
184
192
let warn_after = self . inner . warn_after ;
185
193
let limit_opt = self . inner . limit . unwrap ( & operation_name, "limit" ) ;
186
194
let redact_log_urls = self . inner . redact_log_urls ;
195
+ let max_delay = self . inner . max_delay ;
187
196
let timeout = self . timeout ;
188
197
189
198
trace ! ( logger, "Run with retry: {}" , operation_name) ;
@@ -196,6 +205,7 @@ where
196
205
warn_after,
197
206
limit_opt,
198
207
redact_log_urls,
208
+ max_delay,
199
209
move || {
200
210
try_it ( )
201
211
. timeout ( timeout)
@@ -227,6 +237,7 @@ impl<I, E> RetryConfigNoTimeout<I, E> {
227
237
let warn_after = self . inner . warn_after ;
228
238
let limit_opt = self . inner . limit . unwrap ( & operation_name, "limit" ) ;
229
239
let redact_log_urls = self . inner . redact_log_urls ;
240
+ let max_delay = self . inner . max_delay ;
230
241
231
242
trace ! ( logger, "Run with retry: {}" , operation_name) ;
232
243
@@ -238,6 +249,7 @@ impl<I, E> RetryConfigNoTimeout<I, E> {
238
249
warn_after,
239
250
limit_opt,
240
251
redact_log_urls,
252
+ max_delay,
241
253
// No timeout, so all errors are inner errors
242
254
move || try_it ( ) . map_err ( TimeoutError :: Inner ) ,
243
255
)
@@ -280,6 +292,7 @@ fn run_retry<O, E, F, R>(
280
292
warn_after : u64 ,
281
293
limit_opt : Option < usize > ,
282
294
redact_log_urls : bool ,
295
+ max_delay : Duration ,
283
296
mut try_it_with_timeout : F ,
284
297
) -> impl Future < Output = Result < O , TimeoutError < E > > > + Send
285
298
where
@@ -292,7 +305,7 @@ where
292
305
293
306
let mut attempt_count = 0 ;
294
307
295
- Retry :: spawn ( retry_strategy ( limit_opt, RETRY_DEFAULT_LIMIT ) , move || {
308
+ Retry :: spawn ( retry_strategy ( limit_opt, max_delay ) , move || {
296
309
let operation_name = operation_name. clone ( ) ;
297
310
let logger = logger. clone ( ) ;
298
311
let condition = condition. clone ( ) ;
0 commit comments