#[non_exhaustive]pub struct RetryPolicy {
pub max_attempts: u32,
pub base_delay: Duration,
pub multiplier: f64,
pub jitter: f64,
pub max_delay: Duration,
pub max_retry_after: Duration,
}Expand description
Retry policy for [super::ProviderSet] dispatch, opt-in via
crate::Providers::builder().retry(..).
When configured, a candidate provider that returns
FinanceError::RateLimited is
retried in place — honoring the error’s retry_after hint when present
(capped by max_retry_after), or this policy’s own
exponential-backoff-plus-jitter delay otherwise — up to max_attempts
times before dispatch falls through to the next routed provider (or
fails, if it was the last).
Other error kinds are never retried by this policy: a RateLimited is the
one error a policy-level retry can reliably fix by waiting; anything else
(auth failures, 5xx, not-found, …) is left to the existing
sequential/parallel provider fallback.
Default is no retry — a Providers built without
calling .retry(..) behaves exactly as before this policy existed.
§Example
use finance_query::{Providers, RetryPolicy};
use std::time::Duration;
let providers = Providers::builder()
.retry(RetryPolicy::new(3).base_delay(Duration::from_millis(500)))
.build()
.await?;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_attempts: u32Maximum number of attempts per provider candidate, including the
first try. Values below 1 are treated as 1 (no retry).
base_delay: DurationDelay before the first retry when the error carries no retry_after
hint. Default: 500ms.
multiplier: f64Multiplier applied to the delay after each retry (clamped to at least
1.0). Default: 2.0.
jitter: f64Jitter fraction (0.0..=1.0) applied to the computed delay so many
concurrent callers don’t retry in lockstep. Default: 0.2.
max_delay: DurationUpper bound on the computed backoff delay. Default: 30s.
max_retry_after: DurationUpper bound on an explicit retry_after hint. Separate from
max_delay so a legitimate multi-minute hint is honored, while a
hostile or buggy upstream can’t park the caller indefinitely.
Default: 5 minutes.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(max_attempts: u32) -> Self
pub fn new(max_attempts: u32) -> Self
A policy allowing up to max_attempts tries per candidate provider,
with sane defaults for the rest (500ms base delay, 2x multiplier, 20%
jitter, 30s cap).
Sourcepub fn base_delay(self, delay: Duration) -> Self
pub fn base_delay(self, delay: Duration) -> Self
Override the base delay (see RetryPolicy::base_delay field docs).
Sourcepub fn multiplier(self, multiplier: f64) -> Self
pub fn multiplier(self, multiplier: f64) -> Self
Override the backoff multiplier (see RetryPolicy::multiplier field docs).
Sourcepub fn jitter(self, jitter: f64) -> Self
pub fn jitter(self, jitter: f64) -> Self
Override the jitter fraction (see RetryPolicy::jitter field docs).
Sourcepub fn max_delay(self, max_delay: Duration) -> Self
pub fn max_delay(self, max_delay: Duration) -> Self
Override the max delay cap (see RetryPolicy::max_delay field docs).
Sourcepub fn max_retry_after(self, max_retry_after: Duration) -> Self
pub fn max_retry_after(self, max_retry_after: Duration) -> Self
Override the cap on an explicit retry_after hint
(see RetryPolicy::max_retry_after field docs).
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RetryPolicy
Source§impl Debug for RetryPolicy
impl Debug 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more