pub struct RetryPolicy {
pub max_retries: usize,
pub initial_backoff: Duration,
pub max_backoff: Duration,
pub backoff_multiplier: f64,
pub retryable_statuses: Vec<u16>,
}Expand description
Retry policy for failed requests.
Controls exponential backoff behavior for retryable HTTP status codes
and network errors. The backoff duration is calculated as:
initial_backoff * backoff_multiplier^attempt, capped at max_backoff.
§Examples
use crawlkit_engine::http::RetryPolicy;
use std::time::Duration;
let policy = RetryPolicy::default();
assert_eq!(policy.max_retries, 3);
assert!(policy.is_retryable(429));
assert!(!policy.is_retryable(200));Fields§
§max_retries: usizeMaximum number of retry attempts.
initial_backoff: DurationInitial backoff duration.
max_backoff: DurationMaximum backoff duration.
backoff_multiplier: f64Multiplier applied to backoff on each attempt.
retryable_statuses: Vec<u16>HTTP status codes that trigger a retry.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn backoff_duration(&self, attempt: usize) -> Duration
pub fn backoff_duration(&self, attempt: usize) -> Duration
Returns the backoff duration for a given attempt number (0-indexed).
The duration grows exponentially: initial_backoff * multiplier^attempt,
capped at max_backoff.
§Examples
use crawlkit_engine::http::RetryPolicy;
use std::time::Duration;
let policy = RetryPolicy::default();
assert_eq!(policy.backoff_duration(0), Duration::from_secs(1));
assert_eq!(policy.backoff_duration(1), Duration::from_secs(2));
assert_eq!(policy.backoff_duration(10), Duration::from_secs(30)); // cappedSourcepub fn is_retryable(&self, status: u16) -> bool
pub fn is_retryable(&self, status: u16) -> bool
Returns true if the given status code should trigger a retry.
By default retries on: 429 (Too Many Requests), 500, 502, 503, 504.
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<'de> Deserialize<'de> for RetryPolicy
impl<'de> Deserialize<'de> for RetryPolicy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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>
Converts
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>
Converts
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