Struct retry_policies::policies::ExponentialBackoff
source · [−]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
sourceimpl ExponentialBackoff
impl ExponentialBackoff
sourcepub fn builder() -> ExponentialBackoffBuilder
pub fn builder() -> ExponentialBackoffBuilder
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
sourceimpl Clone for ExponentialBackoff
impl Clone for ExponentialBackoff
sourcefn clone(&self) -> ExponentialBackoff
fn clone(&self) -> ExponentialBackoff
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for ExponentialBackoff
impl Debug for ExponentialBackoff
sourceimpl PartialEq<ExponentialBackoff> for ExponentialBackoff
impl PartialEq<ExponentialBackoff> for ExponentialBackoff
sourcefn eq(&self, other: &ExponentialBackoff) -> bool
fn eq(&self, other: &ExponentialBackoff) -> bool
sourceimpl RetryPolicy for ExponentialBackoff
impl RetryPolicy for ExponentialBackoff
sourcefn should_retry(&self, n_past_retries: u32) -> RetryDecision
fn should_retry(&self, n_past_retries: u32) -> RetryDecision
Determine if a task should be retried according to a retry policy.
impl Copy for ExponentialBackoff
impl Eq for ExponentialBackoff
impl StructuralEq for ExponentialBackoff
impl StructuralPartialEq for ExponentialBackoff
Auto Trait Implementations
impl RefUnwindSafe for ExponentialBackoff
impl Send for ExponentialBackoff
impl Sync for ExponentialBackoff
impl Unpin for ExponentialBackoff
impl UnwindSafe for ExponentialBackoff
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more