Runs calls per key through a circuit (see make).
Attributes#
| Attribute | Type | Description |
|---|---|---|
transitions | Stream[Transition] | Every transition from now on; it ends when the breaker's scope closes. A slow reader loses the oldest past 128. |
Functions#
__init__#
__init__(store, pubsub, policy, open_duration, max_open_duration, on_store_error) -> None| Parameter | Type | Description |
|---|---|---|
store | CircuitBreakerStoreService | |
pubsub | PubSub[Take[Transition]] | |
policy | TripPolicy | |
open_duration | OpenDuration | |
max_open_duration | Duration | |
on_store_error | OnStoreError |
def __init__( # noqa: PLR0917
self,
store: CircuitBreakerStoreService,
pubsub: PubSub[Take[Transition]],
policy: TripPolicy,
open_duration: OpenDuration,
max_open_duration: Duration,
on_store_error: OnStoreError,
) -> None:
self._store = store
self._pubsub = pubsub
self._policy = policy
self._open_duration = _open_duration(open_duration)
self._max_open = max_open_duration
self._on_store_error = on_store_errorstate#
state(key) -> Effect[State, CircuitBreakerError]key's state now.
| Parameter | Type | Description |
|---|---|---|
key | str |
Returns Effect[State, CircuitBreakerError]
def state(self, key: str) -> Effect[State, CircuitBreakerError]:
"""``key``'s state now."""
return self._store.state(key)execute#
execute[R2 = Never](effect: None = None, /, *, key: str, classify: Classifier[Any, Any, R2] | None = None, on_rejection: OnRejection = 'fail') -> Executor[R2]
execute[A, E, R, R2 = Never](effect: Effect[A, E, R], /, *, key: str, classify: Classifier[A, E, R2] | None = None, on_rejection: OnRejection = 'fail') -> Effect[A, E | CircuitBreakerError, R | R2]Run effect through key's circuit: rejected with
CircuitOpen while it is open and CircuitHalfOpen while its
probe runs (or, with on_rejection="allow", run unrecorded),
else run and counted by classify. Without effect, the
function doing that for .pipe.
| Parameter | Type | Description |
|---|---|---|
effect | = None | |
key | ||
classify | = None | |
on_rejection | = 'fail' |
@overload
def execute[R2 = Never](
self,
effect: None = None,
/,
*,
key: str,
classify: Classifier[Any, Any, R2] | None = None,
on_rejection: OnRejection = "fail",
) -> Executor[R2]: ...
@overload
def execute[A, E, R, R2 = Never](
self,
effect: Effect[A, E, R],
/,
*,
key: str,
classify: Classifier[A, E, R2] | None = None,
on_rejection: OnRejection = "fail",
) -> Effect[A, E | CircuitBreakerError, R | R2]: ...
def execute(
self,
effect: Effect[Any, Any, Any] | None = None,
/,
*,
key: str,
classify: Classifier[Any, Any, Any] | None = None,
on_rejection: OnRejection = "fail",
) -> Executor[Any] | Effect[Any, Any, Any]:
"""Run ``effect`` through ``key``'s circuit: rejected with
``CircuitOpen`` while it is open and ``CircuitHalfOpen`` while its
probe runs (or, with ``on_rejection="allow"``, run unrecorded),
else run and counted by ``classify``. Without ``effect``, the
function doing that for ``.pipe``."""
if effect is None:
return Executor(self, key, classify, on_rejection)
require_effect(effect, "effect")
return self._run(effect, key, classify, on_rejection)