pub struct ExponentialBackoffBuilder { /* private fields */ }
Implementations§
Source§impl ExponentialBackoffBuilder
impl ExponentialBackoffBuilder
Sourcepub fn retry_bounds(
self,
min_retry_interval: Duration,
max_retry_interval: Duration,
) -> ExponentialBackoffBuilder
pub fn retry_bounds( self, min_retry_interval: Duration, max_retry_interval: Duration, ) -> ExponentialBackoffBuilder
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) -> ExponentialBackoffBuilder
pub fn backoff_exponent(self, exponent: u32) -> ExponentialBackoffBuilder
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§
Source§impl Default for ExponentialBackoffBuilder
impl Default for ExponentialBackoffBuilder
Source§fn default() -> ExponentialBackoffBuilder
fn default() -> ExponentialBackoffBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ExponentialBackoffBuilder
impl RefUnwindSafe for ExponentialBackoffBuilder
impl Send for ExponentialBackoffBuilder
impl Sync for ExponentialBackoffBuilder
impl Unpin for ExponentialBackoffBuilder
impl UnwindSafe for ExponentialBackoffBuilder
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