pub struct DMSCCircuitBreaker { /* private fields */ }Expand description
Basic circuit breaker implementation.
This struct provides a thread-safe circuit breaker that protects against cascading failures by monitoring the success and failure patterns of operations and transitioning between states (Closed, Open, HalfOpen) based on configurable thresholds.
Implementations§
Source§impl DMSCCircuitBreaker
impl DMSCCircuitBreaker
Sourcepub fn new(config: DMSCCircuitBreakerConfig) -> Self
pub fn new(config: DMSCCircuitBreakerConfig) -> Self
Sourcepub fn allow_request(&self) -> bool
pub fn allow_request(&self) -> bool
Determines if a request should be allowed to proceed based on the current circuit breaker state.
- Closed: Always allows requests
- Open: Rejects requests unless timeout has elapsed, then transitions to HalfOpen
- HalfOpen: Allows limited requests to test service health
§Returns
true if the request should be allowed, false otherwise
Sourcepub fn record_success(&self)
pub fn record_success(&self)
Records a successful operation and updates the circuit breaker state if necessary.
Sourcepub fn record_failure(&self)
pub fn record_failure(&self)
Records a failed operation and updates the circuit breaker state if necessary.
Sourcepub async fn execute<F, R>(&self, operation: F) -> DMSCResult<R>where
F: Future<Output = DMSCResult<R>>,
pub async fn execute<F, R>(&self, operation: F) -> DMSCResult<R>where
F: Future<Output = DMSCResult<R>>,
Executes an operation with circuit breaker protection.
This method wraps an async operation and automatically handles success/failure recording and state transitions based on the operation’s result.
§Type Parameters
F: The async future type representing the operationR: The result type of the operation
§Parameters
operation: The async operation to execute with circuit breaker protection
§Returns
The result of the operation, or an error if the circuit breaker is open
Sourcepub fn get_state(&self) -> DMSCCircuitBreakerState
pub fn get_state(&self) -> DMSCCircuitBreakerState
Gets the current state of the circuit breaker.
§Returns
The current DMSCCircuitBreakerState (Closed, Open, or HalfOpen)
Sourcepub fn get_stats(&self) -> DMSCCircuitBreakerMetrics
pub fn get_stats(&self) -> DMSCCircuitBreakerMetrics
Gets the current metrics for the circuit breaker.
§Returns
A DMSCCircuitBreakerMetrics struct containing the current statistics
Sourcepub fn get_config(&self) -> DMSCCircuitBreakerConfig
pub fn get_config(&self) -> DMSCCircuitBreakerConfig
Gets the configuration for the circuit breaker.
§Returns
A reference to the DMSCCircuitBreakerConfig used by this circuit breaker
Sourcepub fn reset(&self)
pub fn reset(&self)
Resets the circuit breaker to its initial state (Closed).
This method resets all counters and transitions the circuit breaker to Closed state.
Sourcepub fn force_open(&self)
pub fn force_open(&self)
Forces the circuit breaker to transition to Open state.
This method immediately opens the circuit breaker, rejecting all requests until the timeout elapses.
Sourcepub fn force_close(&self)
pub fn force_close(&self)
Forces the circuit breaker to transition to Closed state.
This method immediately closes the circuit breaker, allowing all requests to proceed.
pub fn failure_rate(&self) -> f64
pub fn success_rate(&self) -> f64
pub fn total_requests(&self) -> usize
pub fn is_open(&self) -> bool
pub fn is_closed(&self) -> bool
pub fn is_half_open(&self) -> bool
Trait Implementations§
Source§impl<'py> IntoPyObject<'py> for DMSCCircuitBreaker
impl<'py> IntoPyObject<'py> for DMSCCircuitBreaker
Source§type Target = DMSCCircuitBreaker
type Target = DMSCCircuitBreaker
Source§type Output = Bound<'py, <DMSCCircuitBreaker as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <DMSCCircuitBreaker as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for DMSCCircuitBreaker
impl PyClass for DMSCCircuitBreaker
Source§impl PyClassImpl for DMSCCircuitBreaker
impl PyClassImpl for DMSCCircuitBreaker
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// (Closed, Open, HalfOpen) based on configurable thresholds.
const RAW_DOC: &'static CStr = /// (Closed, Open, HalfOpen) based on configurable thresholds.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<DMSCCircuitBreaker>
type ThreadChecker = SendablePyClass<DMSCCircuitBreaker>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyTypeInfo for DMSCCircuitBreaker
impl PyTypeInfo for DMSCCircuitBreaker
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.impl DerefToPyAny for DMSCCircuitBreaker
impl ExtractPyClassWithClone for DMSCCircuitBreaker
Auto Trait Implementations§
impl Freeze for DMSCCircuitBreaker
impl !RefUnwindSafe for DMSCCircuitBreaker
impl Send for DMSCCircuitBreaker
impl Sync for DMSCCircuitBreaker
impl Unpin for DMSCCircuitBreaker
impl !UnwindSafe for DMSCCircuitBreaker
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§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>
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 more§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. 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::RequestSource§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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more