pub struct CircuitBreakerAspect { /* private fields */ }Expand description
Circuit breaker aspect for preventing cascading failures.
Implements the circuit breaker pattern to protect services from repeated failures and allow time for recovery.
§States
- Closed: Normal operation, failures are tracked
- Open: Fast-fail mode after threshold is exceeded
- Half-Open: Testing recovery with limited requests
§Example
ⓘ
use aspect_std::CircuitBreakerAspect;
use aspect_macros::aspect;
use std::time::Duration;
// Open after 5 failures, timeout after 30 seconds
let breaker = CircuitBreakerAspect::new(5, Duration::from_secs(30));
#[aspect(breaker.clone())]
fn call_external_service() -> Result<String, String> {
// This call is protected by the circuit breaker
Ok("success".to_string())
}Implementations§
Source§impl CircuitBreakerAspect
impl CircuitBreakerAspect
Sourcepub fn with_half_open_requests(self, max_requests: usize) -> Self
pub fn with_half_open_requests(self, max_requests: usize) -> Self
Set the maximum number of requests to allow in half-open state.
Sourcepub fn state(&self) -> CircuitState
pub fn state(&self) -> CircuitState
Get the current circuit state.
Trait Implementations§
Source§impl Aspect for CircuitBreakerAspect
impl Aspect for CircuitBreakerAspect
Source§fn around(
&self,
pjp: ProceedingJoinPoint<'_>,
) -> Result<Box<dyn Any>, AspectError>
fn around( &self, pjp: ProceedingJoinPoint<'_>, ) -> Result<Box<dyn Any>, AspectError>
Advice that wraps the entire target function execution. Read more
Source§fn after(&self, _ctx: &JoinPoint, _result: &(dyn Any + 'static))
fn after(&self, _ctx: &JoinPoint, _result: &(dyn Any + 'static))
Advice executed after the target function completes successfully. Read more
Source§fn after_error(&self, _ctx: &JoinPoint, _error: &AspectError)
fn after_error(&self, _ctx: &JoinPoint, _error: &AspectError)
Advice executed when the target function encounters an error. Read more
Source§impl Clone for CircuitBreakerAspect
impl Clone for CircuitBreakerAspect
Source§fn clone(&self) -> CircuitBreakerAspect
fn clone(&self) -> CircuitBreakerAspect
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CircuitBreakerAspect
impl !RefUnwindSafe for CircuitBreakerAspect
impl Send for CircuitBreakerAspect
impl Sync for CircuitBreakerAspect
impl Unpin for CircuitBreakerAspect
impl UnsafeUnpin for CircuitBreakerAspect
impl !UnwindSafe for CircuitBreakerAspect
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