pub struct RetryBuilder<E = BoxError> { /* private fields */ }Expand description
Builder for Retry.
The generic parameter E is the operation error type preserved inside
AttemptFailure::Error. Failure listeners may observe failures, override
the retry decision, or return AttemptFailureDecision::UseDefault to let
the policy decide from configured limits and delay strategy.
Implementations§
Source§impl<E> RetryBuilder<E>
impl<E> RetryBuilder<E>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a builder with default options and no listeners.
§Returns
A retry builder using RetryOptions::default.
Sourcepub fn options(self, options: RetryOptions) -> Self
pub fn options(self, options: RetryOptions) -> Self
Sourcepub fn max_attempts(self, max_attempts: u32) -> Self
pub fn max_attempts(self, max_attempts: u32) -> Self
Sourcepub fn max_retries(self, max_retries: u32) -> Self
pub fn max_retries(self, max_retries: u32) -> Self
Sourcepub fn max_operation_elapsed(
self,
max_operation_elapsed: Option<Duration>,
) -> Self
pub fn max_operation_elapsed( self, max_operation_elapsed: Option<Duration>, ) -> Self
Sourcepub fn max_total_elapsed(self, max_total_elapsed: Option<Duration>) -> Self
pub fn max_total_elapsed(self, max_total_elapsed: Option<Duration>) -> Self
Sourcepub fn delay(self, delay: RetryDelay) -> Self
pub fn delay(self, delay: RetryDelay) -> Self
Sourcepub fn fixed_delay(self, delay: Duration) -> Self
pub fn fixed_delay(self, delay: Duration) -> Self
Sourcepub fn random_delay(self, min: Duration, max: Duration) -> Self
pub fn random_delay(self, min: Duration, max: Duration) -> Self
Sourcepub fn exponential_backoff(self, initial: Duration, max: Duration) -> Self
pub fn exponential_backoff(self, initial: Duration, max: Duration) -> Self
Sourcepub fn exponential_backoff_with_multiplier(
self,
initial: Duration,
max: Duration,
multiplier: f64,
) -> Self
pub fn exponential_backoff_with_multiplier( self, initial: Duration, max: Duration, multiplier: f64, ) -> Self
Sourcepub fn jitter(self, jitter: RetryJitter) -> Self
pub fn jitter(self, jitter: RetryJitter) -> Self
Sourcepub fn jitter_factor(self, factor: f64) -> Self
pub fn jitter_factor(self, factor: f64) -> Self
Sourcepub fn attempt_timeout(self, attempt_timeout: Option<Duration>) -> Self
pub fn attempt_timeout(self, attempt_timeout: Option<Duration>) -> Self
Sourcepub fn attempt_timeout_option(
self,
attempt_timeout: Option<AttemptTimeoutOption>,
) -> Self
pub fn attempt_timeout_option( self, attempt_timeout: Option<AttemptTimeoutOption>, ) -> Self
Sourcepub fn attempt_timeout_policy(self, policy: AttemptTimeoutPolicy) -> Self
pub fn attempt_timeout_policy(self, policy: AttemptTimeoutPolicy) -> Self
Sets the policy used when an attempt times out.
If a timeout duration is already configured, this updates the complete
timeout option. Otherwise the policy is kept and applied when
RetryBuilder::attempt_timeout is called later.
§Parameters
policy: Timeout policy to use.
§Returns
The updated builder.
Sourcepub fn worker_cancel_grace(self, grace: Duration) -> Self
pub fn worker_cancel_grace(self, grace: Duration) -> Self
Sourcepub fn retry_after_hint<H>(self, hint: H) -> Self
pub fn retry_after_hint<H>(self, hint: H) -> Self
Sourcepub fn retry_after_from_error<H>(self, hint: H) -> Self
pub fn retry_after_from_error<H>(self, hint: H) -> Self
Sourcepub fn before_attempt<C>(self, listener: C) -> Self
pub fn before_attempt<C>(self, listener: C) -> Self
Sourcepub fn on_success<C>(self, listener: C) -> Self
pub fn on_success<C>(self, listener: C) -> Self
Sourcepub fn on_failure<F>(self, listener: F) -> Selfwhere
F: BiFunction<AttemptFailure<E>, RetryContext, AttemptFailureDecision> + Send + Sync + 'static,
pub fn on_failure<F>(self, listener: F) -> Selfwhere
F: BiFunction<AttemptFailure<E>, RetryContext, AttemptFailureDecision> + Send + Sync + 'static,
Sourcepub fn on_retry<C>(self, listener: C) -> Self
pub fn on_retry<C>(self, listener: C) -> Self
Registers a listener invoked after a retry delay has been selected.
The listener receives the failed attempt and a context whose
RetryContext::next_delay contains the delay that will be slept before
the next attempt. The listener is observational and cannot change the
retry decision.
§Parameters
listener: Listener receiving the failure and scheduled-retry context.
§Returns
The updated builder.
Sourcepub fn retry_if_error<P>(self, predicate: P) -> Self
pub fn retry_if_error<P>(self, predicate: P) -> Self
Registers an error-only predicate where true means retry.
§Parameters
predicate: Predicate applied only toAttemptFailure::Error.
§Returns
The updated builder.
Sourcepub fn on_error<C>(self, listener: C) -> Self
pub fn on_error<C>(self, listener: C) -> Self
Registers a listener invoked when the retry flow returns RetryError.
§Parameters
listener: Observational listener that cannot resume the retry flow.
§Returns
The updated builder.
Sourcepub fn abort_on_timeout(self) -> Self
pub fn abort_on_timeout(self) -> Self
Aborts the retry flow when a configured per-attempt timeout expires.
Max-elapsed effective timeouts are not controlled by this policy and stop
with crate::RetryErrorReason::MaxOperationElapsedExceeded.
§Returns
The updated builder.
Sourcepub fn retry_on_timeout(self) -> Self
pub fn retry_on_timeout(self) -> Self
Retries configured per-attempt timeouts while limits allow it.
Max-elapsed effective timeouts are not controlled by this policy and stop
with crate::RetryErrorReason::MaxOperationElapsedExceeded.
§Returns
The updated builder.
Sourcepub fn isolate_listener_panics(self) -> Self
pub fn isolate_listener_panics(self) -> Self
Sourcepub fn build(self) -> Result<Retry<E>, RetryConfigError>
pub fn build(self) -> Result<Retry<E>, RetryConfigError>
Builds and validates the retry policy.
§Returns
A validated Retry.
§Errors
Returns RetryConfigError when options are invalid.
Trait Implementations§
Auto Trait Implementations§
impl<E> Freeze for RetryBuilder<E>
impl<E = Box<dyn Error + Sync + Send>> !RefUnwindSafe for RetryBuilder<E>
impl<E> Send for RetryBuilder<E>
impl<E> Sync for RetryBuilder<E>
impl<E> Unpin for RetryBuilder<E>
impl<E> UnsafeUnpin for RetryBuilder<E>
impl<E = Box<dyn Error + Sync + Send>> !UnwindSafe for RetryBuilder<E>
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
Source§impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
Source§fn into_config_default(self) -> T
fn into_config_default(self) -> T
T.