pub struct CircuitBreaker { /* private fields */ }Expand description
Per-service circuit breaker: rolling-window error-rate trip, single-probe half-open. Cheaply cloneable; clones share one state machine.
Implementations§
Source§impl CircuitBreaker
impl CircuitBreaker
Sourcepub fn new(service_id: String) -> Self
pub fn new(service_id: String) -> Self
Create a breaker for service_id with default tuning and no metrics.
Sourcepub fn with_config(
service_id: String,
config: CircuitBreakerConfig,
metrics: Option<ServiceMetrics>,
) -> Self
pub fn with_config( service_id: String, config: CircuitBreakerConfig, metrics: Option<ServiceMetrics>, ) -> Self
Create a breaker with explicit tuning and an optional metrics sink for state-transition counters.
Sourcepub fn is_open(&self) -> bool
pub fn is_open(&self) -> bool
Whether the circuit is currently rejecting calls.
A single probe is admitted when the cooldown elapses: the first caller
after cooldown transitions Open → HalfOpen and is let through
(false); every other caller is rejected (true) until that probe
resolves via Self::record_success or Self::record_failure.
Sourcepub fn record_success(&self)
pub fn record_success(&self)
Record a successful call. In half-open this closes the breaker and clears the rolling window.
Sourcepub fn record_failure(&self)
pub fn record_failure(&self)
Record a failed call. Trips Closed → Open when the rolling-window error rate crosses the threshold, and re-opens immediately on a failed half-open probe.
Trait Implementations§
Source§impl Clone for CircuitBreaker
impl Clone for CircuitBreaker
Source§fn clone(&self) -> CircuitBreaker
fn clone(&self) -> CircuitBreaker
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CircuitBreaker
impl RefUnwindSafe for CircuitBreaker
impl Send for CircuitBreaker
impl Sync for CircuitBreaker
impl Unpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].