pub struct CircuitBreaker {
state: BreakerState,
failure_threshold: u32,
reset_timeout: Duration,
half_open_max_calls: u32,
backend_name: &'static str,
}Expand description
Circuit breaker for storage backends.
Fields§
§state: BreakerState§failure_threshold: u32§reset_timeout: Duration§half_open_max_calls: u32§backend_name: &'static strImplementations§
Source§impl CircuitBreaker
impl CircuitBreaker
Sourcepub fn new(config: &StorageResilienceConfig, backend_name: &'static str) -> Self
pub fn new(config: &StorageResilienceConfig, backend_name: &'static str) -> Self
Creates a new circuit breaker with the given configuration.
Sourcepub fn allow(&mut self) -> bool
pub fn allow(&mut self) -> bool
Checks if a request is allowed through the circuit breaker.
Returns true if the request should proceed, false if rejected.
Sourcepub fn on_success(&mut self)
pub fn on_success(&mut self)
Records a successful operation, potentially closing the circuit.
Sourcepub fn on_failure(&mut self) -> bool
pub fn on_failure(&mut self) -> bool
Records a failed operation, potentially opening the circuit.
Returns true if the circuit just opened (tripped).
Sourcepub const fn state_value(&self) -> u8
pub const fn state_value(&self) -> u8
Returns the current state as a numeric value for metrics.
- 0: Closed
- 1: Open
- 2: Half-Open
Sourcepub const fn backend_name(&self) -> &'static str
pub const fn backend_name(&self) -> &'static str
Returns the backend name.
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 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<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> 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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
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>,
Applies the layer to a service and wraps it in [
Layered].