pub struct RetryPolicy {
pub max_attempts: u32,
pub initial_delay: Duration,
pub max_delay: Duration,
pub backoff_multiplier: f64,
pub jitter_factor: f64,
pub max_total_duration: Option<Duration>,
}Expand description
Policy for retrying failed operations with exponential backoff
Fields§
§max_attempts: u32Maximum number of retry attempts (0 = no retries)
initial_delay: DurationInitial delay before first retry
max_delay: DurationMaximum delay between retries
backoff_multiplier: f64Multiplier for exponential backoff (typically 2.0)
jitter_factor: f64Add random jitter to prevent thundering herd (0.0 - 1.0) 0.0 = no jitter, 1.0 = full jitter (delay * random(0-1))
max_total_duration: Option<Duration>Maximum total duration for all retries
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(max_attempts: u32, initial_delay: Duration) -> Self
pub fn new(max_attempts: u32, initial_delay: Duration) -> Self
Create a new retry policy with custom settings
Sourcepub fn aggressive() -> Self
pub fn aggressive() -> Self
Aggressive retry for critical operations
Sourcepub fn conservative() -> Self
pub fn conservative() -> Self
Conservative retry for expensive operations
Sourcepub fn delay_for_attempt(&self, attempt: u32) -> Duration
pub fn delay_for_attempt(&self, attempt: u32) -> Duration
Calculate delay for a given attempt number (0-indexed)
Sourcepub async fn execute<F, Fut, T, E>(
&self,
operation_name: &str,
operation: F,
) -> Result<T, RuntimeError>
pub async fn execute<F, Fut, T, E>( &self, operation_name: &str, operation: F, ) -> Result<T, RuntimeError>
Execute an async operation with retry logic
§Example
use agent_runtime::retry::RetryPolicy;
use agent_runtime::{RuntimeError, LlmError};
let policy = RetryPolicy::default();
let result = policy.execute(
"fetch_data",
|| async {
// Your operation here - returns Result<T, impl Into<RuntimeError>>
Ok::<String, LlmError>("success".to_string())
}
).await?;Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RetryPolicy
impl Debug for RetryPolicy
Auto Trait Implementations§
impl Freeze for RetryPolicy
impl RefUnwindSafe for RetryPolicy
impl Send for RetryPolicy
impl Sync for RetryPolicy
impl Unpin for RetryPolicy
impl UnwindSafe for RetryPolicy
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
Mutably borrows from an owned value. Read more