pub trait RetryPolicy:
Send
+ Sync
+ Debug {
// Required method
fn on_error(
&self,
loop_start: Instant,
attempt_count: u32,
idempotent: bool,
error: Error,
) -> LoopState;
// Provided methods
fn on_throttle(
&self,
_loop_start: Instant,
_attempt_count: u32,
) -> Option<Error> { ... }
fn remaining_time(
&self,
_loop_start: Instant,
_attempt_count: u32,
) -> Option<Duration> { ... }
}Expand description
Determines how errors are handled in the retry loop.
Implementations of this trait determine if errors are retryable, and for how long the retry loop may continue.
Required Methods§
Sourcefn on_error(
&self,
loop_start: Instant,
attempt_count: u32,
idempotent: bool,
error: Error,
) -> LoopState
fn on_error( &self, loop_start: Instant, attempt_count: u32, idempotent: bool, error: Error, ) -> LoopState
Query the retry policy after an error.
§Parameters
loop_start- when the retry loop started.attempt_count- the number of attempts. This includes the initial attempt. This method called after the first attempt, so the value is always non-zero.idempotent- iftrueassume the operation is idempotent. Many more errors are retryable on idempotent operations.error- the last error when attempting the request.
Provided Methods§
Sourcefn on_throttle(
&self,
_loop_start: Instant,
_attempt_count: u32,
) -> Option<Error>
fn on_throttle( &self, _loop_start: Instant, _attempt_count: u32, ) -> Option<Error>
Query the retry policy after a retry attempt is throttled.
Retry attempts may be throttled before they are even sent out. The retry policy may choose to treat these as normal errors, consuming attempts, or may prefer to ignore them and always return LoopState::Continue.
§Parameters
loop_start- when the retry loop started.attempt_count- the number of attempts. This method is never called before the first attempt.
Sourcefn remaining_time(
&self,
_loop_start: Instant,
_attempt_count: u32,
) -> Option<Duration>
fn remaining_time( &self, _loop_start: Instant, _attempt_count: u32, ) -> Option<Duration>
The remaining time in the retry policy.
For policies based on time, this returns the remaining time in the
policy. The retry loop can use this value to adjust the next RPC
timeout. For policies that are not time based this returns None.
§Parameters
loop_start- when the retry loop started.attempt_count- the number of attempts. This method is called before the first attempt, so the first value is zero.