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: tuple[type[Exception], ...] | None = None, ignored_exceptions: tuple[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. Mutually exclusive with
|
ignored_exceptions
|
exclusive with |
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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
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
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |