pub struct RetryExecutorBuilder<E = BoxError> { /* private fields */ }Expand description
Builder for RetryExecutor.
The generic parameter E is the application error type that the resulting
executor will pass errors to. If no decider is provided, the built executor retries
every application error until limits stop execution.
Implementations§
Source§impl<E> RetryExecutorBuilder<E>
impl<E> RetryExecutorBuilder<E>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a builder with default options and a retry-all decider.
§Parameters
This function has no parameters.
§Returns
A builder with RetryOptions::default and no listeners.
Sourcepub fn options(self, options: RetryOptions) -> Self
pub fn options(self, options: RetryOptions) -> Self
Replaces all options with an existing option snapshot.
§Parameters
options: Retry options to install in the builder.
§Returns
The updated builder.
§Errors
This method does not return errors immediately. Validation occurs in
RetryExecutorBuilder::build.
Sourcepub fn max_attempts(self, max_attempts: u32) -> Self
pub fn max_attempts(self, max_attempts: u32) -> Self
Sets the maximum number of attempts.
§Parameters
max_attempts: Maximum attempts, including the initial attempt.
§Returns
The updated builder.
§Errors
This method records a configuration error when max_attempts is zero.
The error is returned later by RetryExecutorBuilder::build.
Sourcepub fn max_elapsed(self, max_elapsed: Option<Duration>) -> Self
pub fn max_elapsed(self, max_elapsed: Option<Duration>) -> Self
Sourcepub fn delay(self, delay: RetryDelay) -> Self
pub fn delay(self, delay: RetryDelay) -> Self
Sets the base delay strategy.
§Parameters
delay: Base delay strategy to use between attempts.
§Returns
The updated builder.
§Errors
This method does not return errors immediately. RetryDelay validation occurs
in RetryExecutorBuilder::build.
Sourcepub fn jitter(self, jitter: RetryJitter) -> Self
pub fn jitter(self, jitter: RetryJitter) -> Self
Sets the jitter strategy.
§Parameters
jitter: RetryJitter strategy to apply to each base delay.
§Returns
The updated builder.
§Errors
This method does not return errors immediately. RetryJitter validation occurs
in RetryExecutorBuilder::build.
Sourcepub fn jitter_factor(self, factor: f64) -> Self
pub fn jitter_factor(self, factor: f64) -> Self
Sets the jitter strategy from a relative factor.
§Parameters
factor: Relative jitter range. Valid values are finite and within[0.0, 1.0].
§Returns
The updated builder.
§Errors
This method does not return errors immediately. Factor validation occurs
in RetryExecutorBuilder::build.
Sourcepub fn retry_if<P>(self, retry_tester: P) -> Self
pub fn retry_if<P>(self, retry_tester: P) -> Self
Uses a boolean retry tester where true means retry.
§Parameters
retry_tester: Predicate that receives the application error and attempt context. Returningtruemaps toRetryDecision::Retry; returningfalsemaps toRetryDecision::Abort.
§Returns
The updated builder.
§Errors
This method does not return errors.
§Panics
The built executor propagates any panic raised by retry_tester.
Sourcepub fn retry_decide<B>(self, decider: B) -> Self
pub fn retry_decide<B>(self, decider: B) -> Self
Chooses RetryDecision for each failed attempt from the error and
RetryAttemptContext.
§Parameters
decider: AnyBiFunctionover the application error andRetryAttemptContext(including closures); it is converted withBiFunction::into_arc. The decider itself must beSend + Sync + 'static; the application error typeEis not required to be'static. If type inference fails for a closure, annotate parameters (for example|e: &E, ctx: &RetryAttemptContext|).
§Returns
The updated builder.
§Errors
This method does not return errors.
§Panics
The built executor propagates any panic raised by decider.
Sourcepub fn on_retry<F>(self, listener: F) -> Self
pub fn on_retry<F>(self, listener: F) -> Self
Registers a listener invoked before retry sleep.
§Parameters
listener: Callback invoked withRetryContextplus the triggeringRetryAttemptFailureafter a failed attempt and before sleeping.
§Returns
The updated builder.
§Errors
This method does not return errors.
§Panics
The built executor propagates any panic raised by listener.
Sourcepub fn on_success<F>(self, listener: F) -> Self
pub fn on_success<F>(self, listener: F) -> Self
Registers a listener invoked when the operation succeeds.
§Parameters
listener: Callback invoked with aRetrySuccessContextwhen the operation eventually succeeds.
§Returns
The updated builder.
§Errors
This method does not return errors.
§Panics
The built executor propagates any panic raised by listener.
Sourcepub fn on_failure<F>(self, listener: F) -> Self
pub fn on_failure<F>(self, listener: F) -> Self
Registers a listener invoked when retry limits are exhausted.
§Parameters
listener: Callback invoked withRetryFailureContextmetadata plusOption<RetryAttemptFailure<E>>when retry limits stop execution.
§Returns
The updated builder.
§Errors
This method does not return errors.
§Panics
The built executor propagates any panic raised by listener.
Sourcepub fn on_abort<F>(self, listener: F) -> Self
pub fn on_abort<F>(self, listener: F) -> Self
Registers a listener invoked when the retry decider aborts retrying.
§Parameters
listener: Callback invoked withRetryAbortContextmetadata plus the failure when the retry decider aborts retrying.
§Returns
The updated builder.
§Errors
This method does not return errors.
§Panics
The built executor propagates any panic raised by listener.
Sourcepub fn build(self) -> Result<RetryExecutor<E>, RetryConfigError>
pub fn build(self) -> Result<RetryExecutor<E>, RetryConfigError>
Builds and validates the executor.
§Parameters
This method has no parameters.
§Returns
A validated RetryExecutor.
§Errors
Returns RetryConfigError when max_attempts was set to zero or when
delay or jitter validation fails.