pub trait RetryPolicy<E> {
// Required method
fn decide(
&self,
failure: AttemptFailure<'_, E>,
proposed: RetryDecision,
attempt: usize,
) -> RetryDecision;
}Expand description
Decides what the runner does with a failed attempt.
The runner classifies the failure on its own and passes its verdict as
proposed; the policy returns the decision to apply, which is proposed
itself unless it wants to override it:
RetryDecision::Fatalends the run and returns the original error, the one the closure produced or the commit error, never something the policy made up.RetryDecision::Fdbhands that error tofdb_transaction_on_error, which judges retryability and applies the backoff.RetryDecision::Retrydoes the same with code 1020 (not_committed), which is retryable by definition.
A policy cannot corrupt the
MaybeCommitted flag handed to the closure: it is
computed from the original error before the policy is consulted.
§Example: cap the number of attempts
use foundationdb::runner::{AttemptFailure, RetryPolicy};
use foundationdb::{FdbBindingError, RetryDecision};
struct MaxAttempts(usize);
impl RetryPolicy<FdbBindingError> for MaxAttempts {
fn decide(
&self,
_failure: AttemptFailure<'_, FdbBindingError>,
proposed: RetryDecision,
attempt: usize,
) -> RetryDecision {
if attempt + 1 >= self.0 {
RetryDecision::Fatal
} else {
proposed
}
}
}Required Methods§
Sourcefn decide(
&self,
failure: AttemptFailure<'_, E>,
proposed: RetryDecision,
attempt: usize,
) -> RetryDecision
fn decide( &self, failure: AttemptFailure<'_, E>, proposed: RetryDecision, attempt: usize, ) -> RetryDecision
Returns the decision to apply for failure, proposed being what the
runner would do on its own.