pub struct RetryPolicy {
pub max_retries: usize,
pub base_delay: Duration,
pub max_delay: Duration,
pub backoff_multiplier: f64,
}
Expand description
Retry policy configuration for handling transient failures.
This struct configures how the SDK should retry failed requests, including the number of retries, delay between attempts, and backoff strategy.
§Examples
use serp_sdk::RetryPolicy;
use std::time::Duration;
// Default policy: 3 retries with exponential backoff
let default_policy = RetryPolicy::default();
// Custom policy: 5 retries with longer delays
let custom_policy = RetryPolicy::new(5)
.with_base_delay(Duration::from_millis(500))
.with_max_delay(Duration::from_secs(60))
.with_backoff_multiplier(1.5);
Fields§
§max_retries: usize
Maximum number of retry attempts
base_delay: Duration
Base delay before the first retry attempt
max_delay: Duration
Maximum delay between retry attempts
backoff_multiplier: f64
Multiplier for exponential backoff calculation
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn with_base_delay(self, delay: Duration) -> Self
pub fn with_base_delay(self, delay: Duration) -> Self
Set the base delay between retries
Sourcepub fn with_max_delay(self, delay: Duration) -> Self
pub fn with_max_delay(self, delay: Duration) -> Self
Set the maximum delay between retries
Sourcepub fn with_backoff_multiplier(self, multiplier: f64) -> Self
pub fn with_backoff_multiplier(self, multiplier: f64) -> Self
Set the backoff multiplier for exponential backoff
Sourcepub fn backoff_duration(&self, attempt: usize) -> Duration
pub fn backoff_duration(&self, attempt: usize) -> Duration
Calculate the backoff duration for a given retry attempt
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