Mirror of https://github.com/roostorg/osprey
github.com/roostorg/osprey
1use backoff::exponential::ExponentialBackoff;
2use std::time::Duration;
3
4#[derive(Clone)]
5pub struct Config {
6 /// The initial retry interval.
7 pub min_delay: Duration,
8 /// The maximum value of the back off period. Once the retry interval reaches this
9 /// value it stops increasing.
10 pub max_delay: Duration,
11 /// The value to multiply the current interval with for each retry attempt.
12 pub multiplier: f64,
13}
14
15impl Config {
16 /// `Default` isn't `const` so we need this workaround, see:
17 /// https://stackoverflow.com/a/72467679
18 pub const fn new_const_default() -> Self {
19 Self {
20 min_delay: Duration::from_secs(1),
21 max_delay: Duration::from_secs(60 * 5),
22 multiplier: 2.0,
23 }
24 }
25}
26
27impl Default for Config {
28 fn default() -> Self {
29 Self::new_const_default()
30 }
31}
32
33impl From<Config> for ExponentialBackoff<backoff::SystemClock> {
34 fn from(val: Config) -> Self {
35 ExponentialBackoff {
36 initial_interval: val.min_delay,
37 multiplier: val.multiplier,
38 max_interval: val.max_delay,
39 // XXX: Setting this to Some(duration) will result in the backoff eventually
40 // failing. i.e. inner.next_backoff() will return None!
41 // Do not change this!
42 max_elapsed_time: None,
43 ..Default::default()
44 }
45 }
46}