pub struct RetryPolicy {
pub max_attempts: u32,
pub backoff: BackoffStrategy,
pub timeout: Option<Duration>,
}Expand description
Retry policy for activities.
Configures automatic retry behavior including maximum attempts, backoff strategy, and optional total timeout spanning all attempts.
§Example
use std::time::Duration;
use duroxide::{RetryPolicy, BackoffStrategy};
// Simple retry with defaults (3 attempts, exponential backoff)
let policy = RetryPolicy::new(3);
// Custom policy with timeout and fixed backoff
let policy = RetryPolicy::new(5)
.with_timeout(Duration::from_secs(30))
.with_backoff(BackoffStrategy::Fixed {
delay: Duration::from_secs(1),
});Fields§
§max_attempts: u32Maximum number of attempts (including initial). Must be >= 1.
backoff: BackoffStrategyBackoff strategy between retries.
timeout: Option<Duration>Per-attempt timeout. If set, each activity attempt is raced against this timeout. If timeout fires, returns error immediately (no retry). Retries only occur for activity errors, not timeouts. None = no timeout.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(max_attempts: u32) -> Self
pub fn new(max_attempts: u32) -> Self
Create a new retry policy with specified max attempts and default backoff.
§Panics
Panics if max_attempts is 0.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set per-attempt timeout.
Each activity attempt is raced against this timeout. If the timeout fires before the activity completes, returns an error immediately (no retry). Retries only occur for activity errors, not timeouts.
Sourcepub fn with_backoff(self, backoff: BackoffStrategy) -> Self
pub fn with_backoff(self, backoff: BackoffStrategy) -> Self
Set backoff strategy.
Sourcepub fn delay_for_attempt(&self, attempt: u32) -> Duration
pub fn delay_for_attempt(&self, attempt: u32) -> Duration
Compute delay for given attempt using the configured backoff strategy.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more