pub struct CircuitBreakerConfig {
pub failure_threshold: u32,
pub open_duration: Duration,
pub half_open_successes: u32,
}Expand description
Fault-recovery primitives for resilient agent execution. Configuration parameters for a provider circuit breaker.
All parameters can be tuned based on the provider’s reliability and the acceptable impact of failures on your application.
Fields§
§failure_threshold: u32Number of consecutive failures required to open the circuit.
Default: 5
A lower value makes the circuit more sensitive to failures, while a higher value requires more failures before opening.
open_duration: DurationDuration to keep the circuit open before transitioning to half-open.
Default: 30 seconds
This should be long enough for the provider to recover from whatever caused the failures (e.g., rate limits, temporary outages).
half_open_successes: u32Number of successful requests required in half-open state to close the circuit.
Default: 1
Setting this higher makes recovery testing more conservative, requiring multiple successful requests before fully trusting the provider.
Implementations§
Source§impl CircuitBreakerConfig
impl CircuitBreakerConfig
Sourcepub fn new(
failure_threshold: u32,
open_duration: Duration,
half_open_successes: u32,
) -> CircuitBreakerConfig
pub fn new( failure_threshold: u32, open_duration: Duration, half_open_successes: u32, ) -> CircuitBreakerConfig
Creates a new configuration with all values explicitly set.
§Arguments
failure_threshold- Consecutive failures to trigger circuit openingopen_duration- Time to wait before testing recoveryhalf_open_successes- Successes needed in half-open to close circuit
§Panics
Panics if failure_threshold or half_open_successes are zero,
as this would create an immediately opening circuit.
Sourcepub fn with_failure_threshold(self, threshold: u32) -> CircuitBreakerConfig
pub fn with_failure_threshold(self, threshold: u32) -> CircuitBreakerConfig
Sets the failure threshold.
Returns a new configuration with the updated value.
Sourcepub fn with_open_duration(self, duration: Duration) -> CircuitBreakerConfig
pub fn with_open_duration(self, duration: Duration) -> CircuitBreakerConfig
Sets the open duration.
Returns a new configuration with the updated value.
Sourcepub fn with_half_open_successes(self, successes: u32) -> CircuitBreakerConfig
pub fn with_half_open_successes(self, successes: u32) -> CircuitBreakerConfig
Sets the half-open successes required.
Returns a new configuration with the updated value.
Trait Implementations§
Source§impl Clone for CircuitBreakerConfig
impl Clone for CircuitBreakerConfig
Source§fn clone(&self) -> CircuitBreakerConfig
fn clone(&self) -> CircuitBreakerConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CircuitBreakerConfig
impl Debug for CircuitBreakerConfig
Source§impl Default for CircuitBreakerConfig
impl Default for CircuitBreakerConfig
Source§fn default() -> CircuitBreakerConfig
fn default() -> CircuitBreakerConfig
Creates a default circuit breaker configuration.
The defaults are tuned for general-purpose use:
- 5 failures before opening (reasonable for most APIs)
- 30 second cooldown (enough for temporary issues to resolve)
- 1 success to close (fast recovery testing)
Source§impl PartialEq for CircuitBreakerConfig
impl PartialEq for CircuitBreakerConfig
Source§fn eq(&self, other: &CircuitBreakerConfig) -> bool
fn eq(&self, other: &CircuitBreakerConfig) -> bool
self and other values to be equal, and is used by ==.impl Eq for CircuitBreakerConfig
impl StructuralPartialEq for CircuitBreakerConfig
Auto Trait Implementations§
impl Freeze for CircuitBreakerConfig
impl RefUnwindSafe for CircuitBreakerConfig
impl Send for CircuitBreakerConfig
impl Sync for CircuitBreakerConfig
impl Unpin for CircuitBreakerConfig
impl UnsafeUnpin for CircuitBreakerConfig
impl UnwindSafe for CircuitBreakerConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.