pub struct CircuitBreaker { /* private fields */ }Expand description
Circuit Breaker
Thread-safe, can be shared across multiple async tasks (Arc<CircuitBreaker>).
Implementations§
Source§impl CircuitBreaker
impl CircuitBreaker
Sourcepub fn new(config: CircuitBreakerConfig) -> CircuitBreaker
pub fn new(config: CircuitBreakerConfig) -> CircuitBreaker
Create a circuit breaker with an explicit configuration.
Sourcepub fn default_config() -> CircuitBreaker
pub fn default_config() -> CircuitBreaker
Create a circuit breaker with default configuration.
Sourcepub fn is_open(&self) -> bool
pub fn is_open(&self) -> bool
Pure query: check whether currently in Open state (does not change any state).
For monitoring and logging only; does not trigger state transitions.
Sourcepub fn try_advance(&self) -> bool
pub fn try_advance(&self) -> bool
Attempt to advance state: if Open and timeout has elapsed, transition to HalfOpen automatically.
Returns true if the request should be rejected (still in Open state),
returns false if processing may proceed (Closed or HalfOpen).
In HalfOpen state, at most 1 probe request is allowed concurrently, avoiding thundering herd during recovery.
Callers should invoke record_success() or record_failure() after the request completes,
which will automatically release the probe quota.
If the request is rejected, callers should invoke record_rejected() to update statistics.
Sourcepub fn record_rejected(&self)
pub fn record_rejected(&self)
Record a rejected request (while in Open state).
Sourcepub fn rejected_count(&self) -> u32
pub fn rejected_count(&self) -> u32
Get the total number of rejected requests (for monitoring).
Sourcepub fn record_success(&self)
pub fn record_success(&self)
Record a successful call.
Sourcepub fn record_failure(&self)
pub fn record_failure(&self)
Record a failed call.
Sourcepub fn state_name(&self) -> &'static str
pub fn state_name(&self) -> &'static str
Get a human-readable description of the current state (for logging/monitoring).
Sourcepub fn consecutive_failures(&self) -> u32
pub fn consecutive_failures(&self) -> u32
Get the current consecutive failure count (meaningful only in Closed state).
Trait Implementations§
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
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 moreSource§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>
T in a tonic::Request