pub struct CircuitBreaker { /* private fields */ }Expand description
A RetryPolicy that stops retrying after threshold consecutive
failures and stays silent for a cooldown window before resetting.
§States
- Closed (normal): forwards calls, increments a failure counter on
each error, and applies an exponential back-off up to
threshold − 1attempts. On thethreshold-th consecutive failure the breaker trips. - Open (tripped): rejects every call immediately (
Break) for the duration ofcooldown. - Reset: once
cooldownhas elapsed the breaker closes again and the failure counter resets to zero.
Because RetryPolicy has no success callback the breaker cannot
distinguish a successful probe from a clean run; the counter simply
resets when the cooldown expires. For a full half-open probe you can
wrap CircuitBreaker in a custom RetryPolicy.
§Example
use ferogram::retry::CircuitBreaker;
use std::time::Duration;
// Trip after 5 consecutive errors; stay open for 30 s.
let policy = CircuitBreaker::new(5, Duration::from_secs(30));Implementations§
Trait Implementations§
Source§impl RetryPolicy for CircuitBreaker
impl RetryPolicy for CircuitBreaker
Source§fn should_retry(&self, _ctx: &RetryContext) -> ControlFlow<(), Duration>
fn should_retry(&self, _ctx: &RetryContext) -> ControlFlow<(), Duration>
Decide whether to retry the failed request. Read more
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more