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.

__init__(name)[source]

Creates a new instance identified by name.

property name: str

Returns a human friendly name that identifies this state.

Return type

str

abstract property state: aiobreaker.state.CircuitBreakerState

Override this method to retrieve the current circuit breaker state.

Return type

CircuitBreakerState

abstract increment_counter()[source]

Override this method to increase the failure counter by one.

abstract reset_counter()[source]

Override this method to set the failure counter to zero.

abstract property counter: int

Override this method to retrieve the current value of the failure counter.

Return type

int

abstract property opened_at: datetime.datetime

Override this method to retrieve the most recent value of when the circuit was opened.

Return type

datetime

Memory Storage

class aiobreaker.storage.memory.CircuitMemoryStorage(state)[source]

Bases: aiobreaker.storage.base.CircuitBreakerStorage

Implements a CircuitBreakerStorage in local memory.

__init__(state)[source]

Creates a new instance with the given state.

property state: aiobreaker.state.CircuitBreakerState

Returns the current circuit breaker state.

Return type

CircuitBreakerState

increment_counter()[source]

Increases the failure counter by one.

reset_counter()[source]

Sets the failure counter to zero.

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.

increment_counter()[source]

Increases the failure counter by one.

reset_counter()[source]

Sets the failure counter to zero.

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.