Config
Configuration for the Circuit Breaker utility.
| CLASS | DESCRIPTION |
|---|---|
CircuitBreakerConfig |
Tunables for a circuit breaker. |
CircuitBreakerConfig ¶
CircuitBreakerConfig(failure_threshold: int = 5, recovery_timeout: int = 30, success_threshold: int = 3, handled_exceptions: type[Exception] | Iterable[type[Exception]] | None = None, ignored_exceptions: type[Exception] | Iterable[type[Exception]] | None = None, local_cache_max_age: int = 5)
Tunables for a circuit breaker.
All values have sensible defaults, so CircuitBreakerConfig() is a valid
production configuration. Pass an instance to @circuit_breaker(config=...) to
override them.
| PARAMETER | DESCRIPTION |
|---|---|
failure_threshold
|
Number of consecutive failures that trips a closed circuit to open. Defaults to 5.
TYPE:
|
recovery_timeout
|
Seconds the circuit stays open before allowing a half-open probe. Defaults to 30.
TYPE:
|
success_threshold
|
Number of consecutive probe successes required to close a half-open circuit. Defaults to 3.
TYPE:
|
handled_exceptions
|
propagates without affecting the circuit. Accepts a single exception type or
an iterable of them (normalized to a tuple). Mutually exclusive with
TYPE:
|
ignored_exceptions
|
exception type or an iterable of them (normalized to a tuple). Mutually
exclusive with
TYPE:
|
local_cache_max_age
|
Seconds a circuit's state is cached in the execution environment before a read-through to the store. Matches the Parameters utility default. Defaults to 5.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
CircuitBreakerConfigError
|
If both |
Example
Only count timeouts and connection errors as failures
1 2 3 4 5 | |
| METHOD | DESCRIPTION |
|---|---|
counts_as_failure |
Decide whether an exception raised by the protected call counts as a circuit failure. |
Source code in aws_lambda_powertools/utilities/circuit_breaker_alpha/config.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
counts_as_failure ¶
counts_as_failure(exception: Exception) -> bool
Decide whether an exception raised by the protected call counts as a circuit failure.
| PARAMETER | DESCRIPTION |
|---|---|
exception
|
The exception raised by the protected function.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in aws_lambda_powertools/utilities/circuit_breaker_alpha/config.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |