How to use CircuitBreaker
mainTo protect an integration point, create a CircuitBreaker instance. It is recommended that these instances live globally within your application scope (e.g., across requests).
Common configuration parameters:
fail_max: The number of consecutive failures before the circuit opens.reset_timeout: The time (in seconds) to wait before attempting to close the circuit.success_threshold: The number of successful requests required to close a half-open circuit.throw_new_error_on_trip: If set toFalse, the circuit breaker will raise the original exception that caused the trip instead of aCircuitBreakerErrorwhen the circuit is open.
import pybreaker
# Basic configuration
db_breaker = pybreaker.CircuitBreaker(fail_max=5, reset_timeout=60)
# Configuration with success threshold
db_breaker = pybreaker.CircuitBreaker(fail_max=5, reset_timeout=60, success_threshold=3)
# Prevent CircuitBreakerError by throwing the original error instead
db_breaker = pybreaker.CircuitBreaker(fail_max=5, reset_timeout=60, throw_new_error_on_trip=False)