pub struct ExponentialBackoff {
    pub max_n_retries: u32,
    pub min_retry_interval: Duration,
    pub max_retry_interval: Duration,
    pub backoff_exponent: u32,
}
Expand description

We are using the “decorrelated jitter” approach detailed here: <https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/>

Fields

max_n_retries: u32

Maximum number of allowed retries attempts.

min_retry_interval: Duration

Minimum waiting time between two retry attempts (it can end up being lower due to jittering).

max_retry_interval: Duration

Maximum waiting time between two retry attempts.

backoff_exponent: u32

Growing factor governing how fast the retry interval increases with respect to the number of failed attempts. If set to 3:

  • first retry: 3^0 = 1
  • second retry: 3^1 = 3
  • third retry: 3^2 = 9 …

Implementations

Returns a builder.

Example
use retry_policies::policies::ExponentialBackoff;
use std::time::Duration;

let backoff = ExponentialBackoff::builder()
    .build_with_total_retry_duration(Duration::from_secs(24 * 60 * 60));

assert_eq!(backoff.backoff_exponent, 3);
assert_eq!(backoff.min_retry_interval, Duration::from_secs(1));
assert_eq!(backoff.max_retry_interval, Duration::from_secs(30 * 60));
assert_eq!(backoff.max_n_retries, 55); // calculated

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Determine if a task should be retried according to a retry policy.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.