Storage Backends
Base Class
- class aiobreaker.storage.base.CircuitBreakerStorage(name)[source]
Bases:
abc.ABC
Defines the underlying storage for a circuit breaker - the underlying implementation should be in a subclass that overrides the method this class defines.
- abstract property state: aiobreaker.state.CircuitBreakerState
Override this method to retrieve the current circuit breaker state.
- Return type
- abstract property counter: int
Override this method to retrieve the current value of the failure counter.
- Return type
- abstract property opened_at: datetime.datetime
Override this method to retrieve the most recent value of when the circuit was opened.
- Return type
Memory Storage
- class aiobreaker.storage.memory.CircuitMemoryStorage(state)[source]
Bases:
aiobreaker.storage.base.CircuitBreakerStorage
Implements a CircuitBreakerStorage in local memory.
- property state: aiobreaker.state.CircuitBreakerState
Returns the current circuit breaker state.
- Return type
- property counter
Returns the current value of the failure counter.
- property opened_at
Returns the most recent value of when the circuit was opened.
Redis Storage
- class aiobreaker.storage.redis.CircuitRedisStorage(state, redis_object, namespace=None, fallback_circuit_state=CircuitBreakerState.CLOSED)[source]
Bases:
aiobreaker.storage.base.CircuitBreakerStorage
Implements a CircuitBreakerStorage using redis.
- BASE_NAMESPACE = 'aiobreaker'
- logger = <Logger aiobreaker.storage.redis (WARNING)>
- __init__(state, redis_object, namespace=None, fallback_circuit_state=CircuitBreakerState.CLOSED)[source]
Creates a new instance with the given state and redis object. The redis object should be similar to pyredis’ StrictRedis class. If there are any connection issues with redis, the fallback_circuit_state is used to determine the state of the circuit.
- property state
Returns the current circuit breaker state.
If the circuit breaker state on Redis is missing, re-initialize it with the fallback circuit state and reset the fail counter.
- property counter
Returns the current value of the failure counter.
- property opened_at
Returns a datetime object of the most recent value of when the circuit was opened.