pub struct CircuitBreaker { /* private fields */ }Expand description
Circuit breaker for protecting against cascading failures.
The circuit breaker tracks failures and opens the circuit when the failure threshold is reached, preventing further requests until the reset timeout has elapsed.
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 with_defaults() -> Self
pub fn with_defaults() -> Self
Create a circuit breaker with default configuration.
Sourcepub async fn state(&self) -> CircuitState
pub async fn state(&self) -> CircuitState
Get the current circuit state.
Sourcepub async fn can_execute(&self) -> bool
pub async fn can_execute(&self) -> bool
Check if the circuit allows requests.
Sourcepub async fn call<F, Fut, T>(&self, operation: F) -> Result<T>
pub async fn call<F, Fut, T>(&self, operation: F) -> Result<T>
Execute an async operation with circuit breaker protection.
§Errors
Returns TalosError::CircuitOpen if the circuit is open.
Returns the operation’s error if it fails.
Sourcepub async fn time_until_retry(&self) -> Option<Duration>
pub async fn time_until_retry(&self) -> Option<Duration>
Get the time until the circuit can retry (if open).
Sourcepub fn failure_count(&self) -> usize
pub fn failure_count(&self) -> usize
Get the current failure count.
Sourcepub fn total_calls(&self) -> u64
pub fn total_calls(&self) -> u64
Get total number of calls.
Sourcepub fn total_failures(&self) -> u64
pub fn total_failures(&self) -> u64
Get total number of failures.
Sourcepub fn total_rejections(&self) -> u64
pub fn total_rejections(&self) -> u64
Get total number of rejections (circuit open).
Sourcepub fn failure_rate(&self) -> f64
pub fn failure_rate(&self) -> f64
Get failure rate (0.0 to 1.0).
Sourcepub fn config(&self) -> &CircuitBreakerConfig
pub fn config(&self) -> &CircuitBreakerConfig
Get the circuit breaker configuration.
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
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> 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