pub struct RetryPolicy {
pub max_attempts: u32,
pub base_delay: Duration,
pub kind: RetryKind,
}Expand description
Configurable retry policy with exponential backoff or constant interval.
Fields§
§max_attempts: u32Maximum number of attempts (including the first).
base_delay: DurationBase delay for the first retry.
kind: RetryKindWhether to use exponential or constant delay.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn exponential(
max_attempts: u32,
base_ms: u64,
) -> Result<Self, AgentRuntimeError>
pub fn exponential( max_attempts: u32, base_ms: u64, ) -> Result<Self, AgentRuntimeError>
Sourcepub fn constant(
max_attempts: u32,
delay_ms: u64,
) -> Result<Self, AgentRuntimeError>
pub fn constant( max_attempts: u32, delay_ms: u64, ) -> Result<Self, AgentRuntimeError>
Create a constant (fixed-interval) retry policy.
Every retry waits exactly delay_ms milliseconds regardless of attempt
number, unlike exponential which doubles the delay each time.
§Returns
Ok(RetryPolicy)— on successErr(AgentRuntimeError::Orchestration)— ifmax_attempts == 0ordelay_ms == 0
Sourcepub fn none() -> Self
pub fn none() -> Self
Create a no-retry policy (single attempt, no delay).
Useful for one-shot operations or when the caller manages retry logic externally.
Sourcepub fn is_none(&self) -> bool
pub fn is_none(&self) -> bool
Return true if this policy makes at most one attempt with no delay.
Equivalent to max_attempts == 1 && base_delay == Duration::ZERO.
Sourcepub fn with_max_attempts(self, n: u32) -> Result<Self, AgentRuntimeError>
pub fn with_max_attempts(self, n: u32) -> Result<Self, AgentRuntimeError>
Sourcepub fn max_attempts(&self) -> u32
pub fn max_attempts(&self) -> u32
Return the configured maximum number of attempts.
Sourcepub fn is_no_retry(&self) -> bool
pub fn is_no_retry(&self) -> bool
Return true if this policy performs no retries (max_attempts ≤ 1).
Useful for short-circuiting retry logic in hot paths.
Sourcepub fn will_retry_at_all(&self) -> bool
pub fn will_retry_at_all(&self) -> bool
Return true if this policy allows at least one retry (max_attempts > 1).
Complement of is_no_retry.
Sourcepub fn is_exponential(&self) -> bool
pub fn is_exponential(&self) -> bool
Return true if this policy uses exponential back-off between retries.
Sourcepub fn is_constant(&self) -> bool
pub fn is_constant(&self) -> bool
Return true if this policy uses a constant (fixed-interval) delay between retries.
Sourcepub fn base_delay_ms(&self) -> u64
pub fn base_delay_ms(&self) -> u64
Return the configured base delay in milliseconds.
For constant policies this equals every per-retry delay. For exponential policies this is the delay before the first retry.
Sourcepub fn first_delay_ms(&self) -> u64
pub fn first_delay_ms(&self) -> u64
Return the delay before the first retry in milliseconds.
Alias for base_delay_ms; the name communicates intent more clearly at
call sites that only care about the first-retry delay.
Sourcepub fn is_last_attempt(&self, attempt: u32) -> bool
pub fn is_last_attempt(&self, attempt: u32) -> bool
Return true if attempt is the last allowed attempt for this policy.
attempt is 1-indexed: attempt == max_attempts means no more retries.
Sourcepub fn max_total_delay_ms(&self) -> u64
pub fn max_total_delay_ms(&self) -> u64
Return the sum of all per-attempt delays across all attempts, in milliseconds.
For exponential policies each attempt’s delay is capped at
MAX_RETRY_DELAY. For constant policies every attempt uses
base_delay_ms.
Sourcepub fn delay_sum_ms(&self, n: u32) -> u64
pub fn delay_sum_ms(&self, n: u32) -> u64
Return the sum of delays for the first n attempts, in milliseconds.
If n > max_attempts, only max_attempts delays are summed.
Sourcepub fn avg_delay_ms(&self) -> u64
pub fn avg_delay_ms(&self) -> u64
Return the average delay per attempt in milliseconds.
Returns 0 for policies with no delay (e.g. RetryPolicy::none()).
Sourcepub fn backoff_factor(&self) -> f64
pub fn backoff_factor(&self) -> f64
Return the effective backoff factor per attempt.
Returns 2.0 for exponential policies and 1.0 for constant policies.
Sourcepub fn with_base_delay_ms(self, ms: u64) -> Result<Self, AgentRuntimeError>
pub fn with_base_delay_ms(self, ms: u64) -> Result<Self, AgentRuntimeError>
Return a copy of this policy with the base delay changed to ms milliseconds.
§Errors
Returns Err if ms == 0.
Sourcepub fn delay_ms_for(&self, attempt: u32) -> u64
pub fn delay_ms_for(&self, attempt: u32) -> u64
Return the delay for attempt in whole milliseconds.
Convenience wrapper around delay_for for use in logging and metrics
where a u64 is easier to handle than a Duration.
Sourcepub fn total_max_delay_ms(&self) -> u64
pub fn total_max_delay_ms(&self) -> u64
Return the total maximum delay in milliseconds across all retry attempts.
Sums delay_for(attempt) for every attempt from 1 to max_attempts.
Useful for estimating worst-case latency budgets.
Sourcepub fn attempts_remaining(&self, attempt: u32) -> u32
pub fn attempts_remaining(&self, attempt: u32) -> u32
Return the number of attempts still available after attempt have been made.
Returns 0 once the budget is exhausted (attempt >= max_attempts).
Sourcepub fn can_retry(&self, attempt: u32) -> bool
pub fn can_retry(&self, attempt: u32) -> bool
Return true if another attempt is permitted after attempt failures.
attempt is the number of attempts already made (0-based: 0 means
no attempt has been made yet). Returns false once the budget is
exhausted (i.e. attempt >= max_attempts).
Sourcepub fn delay_for(&self, attempt: u32) -> Duration
pub fn delay_for(&self, attempt: u32) -> Duration
Compute the delay before the given attempt number (1-based).
RetryKind::Exponential:base_delay * 2^(attempt-1), capped atMAX_RETRY_DELAY.RetryKind::Constant: always returnsbase_delay.
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