pub struct CircuitBreaker { /* private fields */ }Expand description
A single per-model circuit breaker.
Implementations§
Source§impl CircuitBreaker
impl CircuitBreaker
Sourcepub fn new(config: CircuitBreakerConfig) -> Self
pub fn new(config: CircuitBreakerConfig) -> Self
Create a new circuit breaker with the given configuration.
Sourcepub fn is_allowed(&self) -> bool
pub fn is_allowed(&self) -> bool
Returns true when a request should be allowed through.
- Closed: always allowed.
- Open: not allowed unless the timeout has elapsed, in which case the breaker transitions to HalfOpen and the probe request is allowed.
- HalfOpen: allowed (the probe).
Sourcepub fn record_success(&self)
pub fn record_success(&self)
Record a successful call outcome and drive state transitions.
Sourcepub fn record_failure(&self)
pub fn record_failure(&self)
Record a failed call outcome and drive state transitions.
Sourcepub fn state(&self) -> CircuitState
pub fn state(&self) -> CircuitState
Return the current state of the circuit breaker.
Sourcepub fn failure_rate(&self) -> f64
pub fn failure_rate(&self) -> f64
Return the failure rate (0.0–1.0) in the current sliding window.
Returns 0.0 if no calls have been recorded yet.
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request