pub struct RetryPolicy { /* private fields */ }Expand description
Decides how often a failed delivery is retried and how long its subscription waits between attempts. A delivery keeps its subscription’s concurrency slot while it waits, so a subscription handling one message at a time retries it before moving on to the next. Delays that would overflow saturate at Duration::MAX, use with_max_delay to cap them.
§Example
use std::time::Duration;
use topmesys::RetryPolicy;
let policy = RetryPolicy::exponential(4, Duration::from_millis(100))
.with_max_delay(Duration::from_millis(500));
assert_eq!(policy.delay(1), Duration::from_millis(100));
assert_eq!(policy.delay(3), Duration::from_millis(400));
assert_eq!(policy.delay(4), Duration::from_millis(500));Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(retries: u32, backoff: Backoff) -> Self
pub fn new(retries: u32, backoff: Backoff) -> Self
Retries a failed delivery up to retries times, waiting according to backoff.
pub fn fixed(retries: u32, delay: Duration) -> Self
pub fn linear(retries: u32, initial: Duration, increment: Duration) -> Self
Sourcepub fn exponential(retries: u32, initial: Duration) -> Self
pub fn exponential(retries: u32, initial: Duration) -> Self
Doubles the delay with every retry, starting at initial.
Sourcepub fn with_max_delay(self, max_delay: Duration) -> Self
pub fn with_max_delay(self, max_delay: Duration) -> Self
Caps every delay at max_delay.
Sourcepub fn with_jitter(self) -> Self
pub fn with_jitter(self) -> Self
Randomises every delay to between half and all of its computed value, so deliveries that failed together don’t retry at the same moment.
pub fn retries(&self) -> u32
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 RetryPolicy
impl Debug for RetryPolicy
Source§impl Default for RetryPolicy
impl Default for RetryPolicy
Source§impl PartialEq for RetryPolicy
impl PartialEq for RetryPolicy
impl StructuralPartialEq for RetryPolicy
Auto Trait Implementations§
impl Freeze for RetryPolicy
impl RefUnwindSafe for RetryPolicy
impl Send for RetryPolicy
impl Sync for RetryPolicy
impl Unpin for RetryPolicy
impl UnsafeUnpin for RetryPolicy
impl UnwindSafe for RetryPolicy
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