Skip to main content

RetryPolicy

Trait RetryPolicy 

Source
pub trait RetryPolicy:
    Debug
    + Send
    + Sync {
    // Required methods
    fn is_expired(
        &self,
        duration_since_start: SignedDuration,
        retry_count: u32,
    ) -> bool;
    fn retry_headers(&self) -> Option<&RetryHeaders>;
    fn retry_status_codes(&self) -> &[StatusCode];
    fn sleep_duration(&self, retry_count: u32) -> SignedDuration;

    // Provided method
    fn wait<'life0, 'async_trait>(
        &'life0 self,
        retry_count: u32,
        retry_after: Option<SignedDuration>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

A retry policy.

In the simple form, the policies need only differ in how they determine if the retry has expired and for how long they should sleep between retries.

wait can be implemented in more complex cases where a simple test of time is not enough.

Required Methods§

Source

fn is_expired( &self, duration_since_start: SignedDuration, retry_count: u32, ) -> bool

Determine if no more retries should be performed.

Must return true if no more retries should be attempted.

Source

fn retry_headers(&self) -> Option<&RetryHeaders>

Get the headers that may indicate how long to wait before retrying. If None is returned, no headers will be checked.

Source

fn retry_status_codes(&self) -> &[StatusCode]

Get the status codes that should trigger retries. When the returned slice is empty, the policy retries these status codes:

  • 408 Request Timeout
  • 429 Too Many Requests
  • 500 Internal Server Error
  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout
Source

fn sleep_duration(&self, retry_count: u32) -> SignedDuration

Determine how long before the next retry should be attempted.

Provided Methods§

Source

fn wait<'life0, 'async_trait>( &'life0 self, retry_count: u32, retry_after: Option<SignedDuration>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

A Future that will wait until the request can be retried.

§Arguments
  • retry_count - the number of times the request has been retried.
  • retry_after - the duration to wait before retrying, if provided by the server response.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§