Circuit Breaker#

Cut the circuit in case a service is down.

class blacksmith.middleware._async.circuit_breaker.AsyncCircuitBreakerMiddleware(threshold: int = 5, ttl: float = 30, listeners: Optional[Iterable[Callable[[str, typing_extensions.Literal[circuit_breaker_created, state_changed, failed, recovered], purgatory.domain.messages.base.Event], None]]] = None, uow: Optional[purgatory.service._async.unit_of_work.AsyncAbstractUnitOfWork] = None, metrics: Optional[blacksmith.domain.model.middleware.prometheus.PrometheusMetrics] = None)#

Prevent cascading failure.

The circuit breaker is based on purgatory, the middleware create one circuit breaker per client_name. The parameters are forwarded to all the clients. This middleware does not give the possibility to adapt a threshold or the time the circuit is opened per clients.

__init__(threshold: int = 5, ttl: float = 30, listeners: Optional[Iterable[Callable[[str, typing_extensions.Literal[circuit_breaker_created, state_changed, failed, recovered], purgatory.domain.messages.base.Event], None]]] = None, uow: Optional[purgatory.service._async.unit_of_work.AsyncAbstractUnitOfWork] = None, metrics: Optional[blacksmith.domain.model.middleware.prometheus.PrometheusMetrics] = None)#
async initialize() None#

Asynchronous initialization of a middleware.

For instance, used to initialize connection to storage backend.

__call__(next: blacksmith.domain.typing.AsyncMiddleware) blacksmith.domain.typing.AsyncMiddleware#

Call self as a function.