pub struct CircuitBreaker { /* private fields */ }Expand description
Implementations§
Source§impl CircuitBreaker
impl CircuitBreaker
Sourcepub fn new(failure_threshold: u32, recovery_secs: u64) -> Self
pub fn new(failure_threshold: u32, recovery_secs: u64) -> Self
Create a new circuit breaker.
failure_threshold— how many consecutive failures open the circuit.recovery_secs— how long the circuit stays Open before testing again.
Sourcepub fn is_available(&mut self, backend: &str) -> bool
pub fn is_available(&mut self, backend: &str) -> bool
Returns true if a request should be forwarded to backend.
Transitions Open → HalfOpen when the recovery window has elapsed.
Sourcepub fn record_success(&mut self, backend: &str)
pub fn record_success(&mut self, backend: &str)
Record a successful response for backend.
Transitions HalfOpen → Closed and resets the failure counter.
Sourcepub fn record_failure(&mut self, backend: &str)
pub fn record_failure(&mut self, backend: &str)
Record a failed response for backend.
In Closed state, increments the counter and opens the circuit when
failure_threshold is reached. In HalfOpen state, immediately
re-opens the circuit and resets the recovery timer.
Sourcepub fn state(&self, backend: &str) -> BreakerState
pub fn state(&self, backend: &str) -> BreakerState
Return the current state for backend (defaults to Closed if unseen).
Auto Trait Implementations§
impl Freeze for CircuitBreaker
impl RefUnwindSafe for CircuitBreaker
impl Send for CircuitBreaker
impl Sync for CircuitBreaker
impl Unpin for CircuitBreaker
impl UnsafeUnpin for CircuitBreaker
impl UnwindSafe for CircuitBreaker
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