pub struct RetryPolicy {
pub max_retries: u32,
pub backoff_initial: Duration,
pub backoff_max: Duration,
pub backoff_jitter: f64,
pub http_statuses: StatusSet,
pub respect_retry_after: bool,
pub max_retry_after: Duration,
pub retry_connection_errors: bool,
pub retry_timeouts: bool,
pub connect_only_before_send: bool,
}Expand description
Retry policy matching the official TypeSafe SDKs.
Default: 2 retries, 500 ms initial backoff, 5 s cap, 25% jitter, HTTP 408/429/5xx,
connection errors, timeouts, and retry-after-ms / Retry-After up to 60 s.
Struct-update from RetryPolicy::default so private fields stay initialized:
RetryPolicy { max_retries: 0, ..RetryPolicy::default() }.
§Examples
use typesafe_rs::RetryPolicy;
let none = RetryPolicy::none();
assert_eq!(none.max_retries, 0);
let conservative = RetryPolicy::conservative();
assert!(!conservative.retry_timeouts);Fields§
§max_retries: u32Maximum retries after the initial attempt. Default: 2.
backoff_initial: DurationFirst backoff delay. Default: 500 ms.
backoff_max: DurationBackoff cap. Default: 5 s.
backoff_jitter: f64Fraction of each backoff randomly subtracted, in [0, 1]. Default: 0.25.
http_statuses: StatusSetHTTP statuses that are retried. Default: 408, 429, 500–599.
respect_retry_after: boolHonor retry-after-ms / Retry-After up to Self::max_retry_after.
max_retry_after: DurationMaximum server-requested delay that will be honored. Default: 60 s.
retry_connection_errors: boolRetry connection failures. Default: true.
retry_timeouts: boolRetry timeouts. Default: true.
connect_only_before_send: boolWhen true, only connection errors that happen before bytes are sent are retried.
Set by RetryPolicy::conservative. Keep the default (false) unless you
want that behaviour; prefer ..RetryPolicy::default() in struct updates.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn conservative() -> Self
pub fn conservative() -> Self
Retry 408/429 and pre-send connection errors only. No 5xx, no timeouts.
Sourcepub fn parse_retry_after(headers: &HeaderMap) -> Option<Duration>
pub fn parse_retry_after(headers: &HeaderMap) -> Option<Duration>
Parse retry-after-ms (preferred) or Retry-After into a delay.
Invalid values are ignored (None).
Sourcepub fn parse_retry_after_at(
headers: &HeaderMap,
now: SystemTime,
) -> Option<Duration>
pub fn parse_retry_after_at( headers: &HeaderMap, now: SystemTime, ) -> Option<Duration>
Self::parse_retry_after with an injected now for HTTP-date values.
Sourcepub fn delay_after_failure(
&self,
attempt: u32,
headers: Option<&HeaderMap>,
) -> Duration
pub fn delay_after_failure( &self, attempt: u32, headers: Option<&HeaderMap>, ) -> Duration
Delay before the next attempt after a zero-based failed attempt.
Sourcepub fn delay_after_failure_with<F>(
&self,
attempt: u32,
headers: Option<&HeaderMap>,
rng: F,
) -> Duration
pub fn delay_after_failure_with<F>( &self, attempt: u32, headers: Option<&HeaderMap>, rng: F, ) -> Duration
Self::delay_after_failure with an injected RNG in [0, 1).
Tests should call this instead of reimplementing backoff math.
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 more