pub struct RetryPolicy { /* private fields */ }Available on crate feature
retry only.Expand description
Retries 429 Too Many Requests, 408 Request Timeout and 5xx responses, and failures to connect.
- It waits as long as the server asks, with
retry-after-ms(milliseconds) orRetry-After(seconds), up toRetryPolicy::max_retry_after(60 s by default). A server that asks for longer gets its response returned at once: waiting less than it asked would likely fail again, and waiting an hour is rarely what a caller wants. - Without those headers it backs off exponentially from
RetryPolicy::base_delay(200 ms), doubling on each retry up toRetryPolicy::max_delay(8 s), with jitter: each delay is picked at random between half and all of it, so that clients that failed together do not retry together.RetryPolicy::jitterturns that off. - It never retries a response marked
Permanent(seeRetryLayer::permanent_429), nor a request whose body is a stream (a streamed file upload), which cannot be sent again.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(max_retries: usize) -> Self
pub fn new(max_retries: usize) -> Self
A policy that retries at most max_retries times (after the first attempt).
Sourcepub fn base_delay(self, delay: Duration) -> Self
pub fn base_delay(self, delay: Duration) -> Self
The first backoff delay, doubled on each retry (default 200 ms).
Sourcepub fn max_delay(self, delay: Duration) -> Self
pub fn max_delay(self, delay: Duration) -> Self
The longest backoff delay (default 8 s). It does not limit how long a server can ask to wait with
Retry-After: that is RetryPolicy::max_retry_after.
Sourcepub fn max_retry_after(self, delay: Duration) -> Self
pub fn max_retry_after(self, delay: Duration) -> Self
The longest wait a server can ask for with Retry-After or retry-after-ms (default 60 s). A response that
asks for longer is not retried but returned.
Sourcepub fn jitter(self, jitter: bool) -> Self
pub fn jitter(self, jitter: bool) -> Self
Whether each backoff delay is picked at random between half and all of it (default true). The waits a
server asks for are never jittered.
Sourcepub fn max_retries(&self) -> usize
pub fn max_retries(&self) -> usize
The number of retries allowed.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§impl Debug for RetryPolicy
impl Debug for RetryPolicy
Source§impl Default for RetryPolicy
Three retries.
impl Default for RetryPolicy
Three retries.
Source§impl<B> Policy<Request<Body>, Response<B>, Box<dyn Error + Sync + Send>> for RetryPolicy
impl<B> Policy<Request<Body>, Response<B>, Box<dyn Error + Sync + Send>> 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
Mutably borrows from an owned value. Read more