Use the @circuit decorator for basic circuit breaking
developThe simplest way to use the library is to decorate a function (synchronous or asynchronous) with @circuit. This sets up a circuit breaker with default settings:
- Failure threshold: 5 subsequent failures.
- Recovery timeout: 30 seconds.
- Expected exception: Any exception inheriting from
Exception. - Name: The name of the decorated function.
When the circuit is open, subsequent calls will raise a CircuitBreaker exception.
from circuitbreaker import circuit
@circuit
def external_call():
...
@circuit
async def async_external_call():
...