Circuit Breaker
Automatic resilience for storage backends with configurable failure thresholds, timeouts, and half-open probing.
How It Works
CLOSED →failure_threshold →OPEN →timeout →HALF_OPEN →success →CLOSED
Configuration
RedisStorage has a built-in circuit breaker. Configuration is via constructor params:
| Parameter | Default | Description |
|---|---|---|
failure_threshold | 5 | Failures before opening the circuit |
recovery_timeout | 30s | Time to wait in OPEN before probing |
half_open_max_calls | 1 | Max probe calls in HALF_OPEN |
Behavior
When the circuit is OPEN, all storage operations raise CircuitBreakerOpenError. The framework catches this and the bot continues running without FSM — handlers still execute, but PatchHelper operations return defaults. When Redis comes back, the circuit transitions through HALF_OPEN back to CLOSED automatically.