-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Calculated break duration for Circuit breaker and Advance Circuit breaker #653
Description
CircuitBreaker and AdvanceCircuitBreaker currently only allow for a fixed break duration. I would like to be able to calculated the break duration based on the number of consecutive "unhealthy" requests made. This would allow the duration to be increased as the downstream system continues to be unavailable. With this I would be able to increase the duration between attempts to interact with the downstream system over time hopefully allowing it to recover. With this I would also be able to reduce log entries for failed requests to the downstream service.
The use case I see for this is a system that is going to be down for awhile do to some catastrophic issue. Like the Retry policy this allows us to wait longer each time before attempting to interact with the system, and using Math.Min allows us to set an upper limit on the wait duration.
Example Usage
Policy.Handle<Exception>().CircuitBreaker(
exceptionsAllowedBeforeBreaking: 5,
durationOfBreak: unhealthyAttempts => TimeSpan.FromSeconds(Math.Min(20 + Math.Pow(2, unhealthyAttempts), /* Max */400)));