Struct retry_policies::policies::ExponentialBackoffBuilder
source · [−]pub struct ExponentialBackoffBuilder { /* private fields */ }
Implementations
sourceimpl ExponentialBackoffBuilder
impl ExponentialBackoffBuilder
sourcepub fn retry_bounds(
self,
min_retry_interval: Duration,
max_retry_interval: Duration
) -> Self
pub fn retry_bounds(
self,
min_retry_interval: Duration,
max_retry_interval: Duration
) -> Self
Add min & max retry interval bounds. Default [1s, 30m].
See ExponentialBackoff::min_retry_interval
, ExponentialBackoff::max_retry_interval
.
Panics if min_retry_interval
> max_retry_interval
.
sourcepub fn backoff_exponent(self, exponent: u32) -> Self
pub fn backoff_exponent(self, exponent: u32) -> Self
Set backoff exponent. Default 3.
sourcepub fn build_with_max_retries(self, n: u32) -> ExponentialBackoff
pub fn build_with_max_retries(self, n: u32) -> ExponentialBackoff
Builds a ExponentialBackoff
with the given maximum retries.
sourcepub fn build_with_total_retry_duration(
self,
total_duration: Duration
) -> ExponentialBackoff
pub fn build_with_total_retry_duration(
self,
total_duration: Duration
) -> ExponentialBackoff
Builds a ExponentialBackoff
with ExponentialBackoff::max_n_retries
calculated
from an approximate total duration. So that after the resultant max_n_retries
we’ll
have (generally) retried past the given total_duration
.
The actual duration will be approximate due to retry jitter, though this calculation is itself deterministic (based off mean jitter).
Example
use retry_policies::policies::ExponentialBackoff;
use std::time::Duration;
let backoff = ExponentialBackoff::builder()
.backoff_exponent(2)
.retry_bounds(Duration::from_secs(1), Duration::from_secs(60 * 60))
// set a retry count so we retry for ~3 hours
.build_with_total_retry_duration(Duration::from_secs(3 * 60 * 60));
// mean delay steps: 1.5s, 3s, 6s, 12s, 24s, 48s, 96s, 192s,
// 384s, 768s, 1536s, 3072s, 3600s, 3600s
// expected total delay: 13342.5s = 3.7h (least number of retries >= 3h)
assert_eq!(backoff.max_n_retries, 14);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for ExponentialBackoffBuilder
impl Send for ExponentialBackoffBuilder
impl Sync for ExponentialBackoffBuilder
impl Unpin for ExponentialBackoffBuilder
impl UnwindSafe for ExponentialBackoffBuilder
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