Skip to main content

RetryPolicy

Struct RetryPolicy 

Source
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: u32

Maximum number of attempts (including the first).

§base_delay: Duration

Base delay for the first retry.

§kind: RetryKind

Whether to use exponential or constant delay.

Implementations§

Source§

impl RetryPolicy

Source

pub fn exponential( max_attempts: u32, base_ms: u64, ) -> Result<Self, AgentRuntimeError>

Create an exponential retry policy.

§Arguments
  • max_attempts — total attempt budget (must be ≥ 1)
  • base_ms — base delay in milliseconds for attempt 1
§Returns
  • Ok(RetryPolicy) — on success
  • Err(AgentRuntimeError::Orchestration) — if max_attempts == 0
Source

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 success
  • Err(AgentRuntimeError::Orchestration) — if max_attempts == 0 or delay_ms == 0
Source

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.

Source

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.

Source

pub fn with_max_attempts(self, n: u32) -> Result<Self, AgentRuntimeError>

Return a copy of this policy with max_attempts changed.

§Errors

Returns Err if n == 0.

Source

pub fn max_attempts(&self) -> u32

Return the configured maximum number of attempts.

Source

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.

Source

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.

Source

pub fn is_exponential(&self) -> bool

Return true if this policy uses exponential back-off between retries.

Source

pub fn is_constant(&self) -> bool

Return true if this policy uses a constant (fixed-interval) delay between retries.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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()).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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).

Source

pub fn delay_for(&self, attempt: u32) -> Duration

Compute the delay before the given attempt number (1-based).

Trait Implementations§

Source§

impl Clone for RetryPolicy

Source§

fn clone(&self) -> RetryPolicy

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RetryPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more