#[non_exhaustive]pub struct RetryPolicy {
pub max_retries: u32,
pub base_delay: Duration,
pub max_delay: Duration,
pub honor_retry_after: bool,
pub max_retry_after: Duration,
pub jitter: bool,
}api only.Expand description
How many times, and how patiently, to retry.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_retries: u32Attempts after the first. Zero disables retrying.
base_delay: DurationDelay before the first retry; doubles each attempt.
max_delay: DurationCeiling on the computed delay.
honor_retry_after: boolWhether to obey a Retry-After header when the server sends one.
max_retry_after: DurationThe longest Retry-After this client will wait out.
Separate from max_delay, which bounds the
computed backoff. Clamping the server’s own instruction to that bound
would be the worst of both: a gateway that says “wait 60 seconds” would
be re-asked after ten, still rate-limited, burning the whole retry
budget without ever waiting long enough to succeed. So a Retry-After
longer than this ends the retries and returns the response instead —
the caller learns it was rate-limited and for how long, which is
something it can act on, rather than a retry storm it cannot see.
jitter: boolWhether to spread retries randomly over the backoff window.
On by default. Without it, every client that saw the same outage retries in the same instant and the recovering server is knocked over again.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn max_retries(self, retries: u32) -> Self
pub fn max_retries(self, retries: u32) -> Self
Sets the number of retries after the first attempt.
Sourcepub fn base_delay(self, delay: Duration) -> Self
pub fn base_delay(self, delay: Duration) -> Self
Sets the delay before the first retry.
Sourcepub fn honor_retry_after(self, honor: bool) -> Self
pub fn honor_retry_after(self, honor: bool) -> Self
Sets whether Retry-After overrides the computed backoff.
Sourcepub fn max_retry_after(self, limit: Duration) -> Self
pub fn max_retry_after(self, limit: Duration) -> Self
Sets the longest Retry-After this client will wait out.
A server asking for longer ends the retries; see
max_retry_after.
Sourcepub fn jitter(self, jitter: bool) -> Self
pub fn jitter(self, jitter: bool) -> Self
Sets whether to spread retries over the backoff window.
Sourcepub fn window_for(&self, attempt: u32) -> Duration
pub fn window_for(&self, attempt: u32) -> Duration
The backoff ceiling for attempt attempt (1-based), capped at
max_delay.
This is the window, not the wait: with jitter on, the actual wait is
drawn from [0, window]. That is the “full jitter” strategy, which
spreads a thundering herd better than adding a small random offset to a
fixed delay.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
impl Copy for RetryPolicy
Source§impl Debug for RetryPolicy
impl Debug for RetryPolicy
Source§impl Default for RetryPolicy
impl Default for RetryPolicy
impl Eq for RetryPolicy
Source§impl PartialEq for RetryPolicy
impl PartialEq for RetryPolicy
impl StructuralPartialEq for RetryPolicy
Auto Trait Implementations§
impl Forget for RetryPolicy
impl Freeze for RetryPolicy
impl Move 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
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
key and return true if they are equal.