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§
Source§impl 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§
Source§impl Clone for ExponentialBackoff
impl Clone for ExponentialBackoff
Source§fn clone(&self) -> ExponentialBackoff
fn clone(&self) -> ExponentialBackoff
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ExponentialBackoff
impl Debug for ExponentialBackoff
Source§impl PartialEq for ExponentialBackoff
impl PartialEq for ExponentialBackoff
Source§impl RetryPolicy for ExponentialBackoff
impl RetryPolicy for ExponentialBackoff
Source§fn 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 StructuralPartialEq for ExponentialBackoff
Auto Trait Implementations§
impl Freeze for ExponentialBackoff
impl RefUnwindSafe for ExponentialBackoff
impl Send for ExponentialBackoff
impl Sync for ExponentialBackoff
impl Unpin for ExponentialBackoff
impl UnwindSafe for ExponentialBackoff
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.