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 !=.

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

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more