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: Iterable[Callable[[str, Literal['circuit_breaker_created', 'state_changed', 'failed', 'recovered'], Event], None]] | None = None, uow: AsyncAbstractUnitOfWork | None = None, metrics: PrometheusMetrics | None = 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: Iterable[Callable[[str, Literal['circuit_breaker_created', 'state_changed', 'failed', 'recovered'], Event], None]] | None = None, uow: AsyncAbstractUnitOfWork | None = None, metrics: PrometheusMetrics | None = None)
async initialize() None

Asynchronous initialization of a middleware.

For instance, used to initialize connection to storage backend.

__call__(next: AsyncMiddleware) AsyncMiddleware

Call self as a function.