-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.x] Add circuit breaker job middleware for unstable services #36473
Conversation
Do you mind if I rename it to |
@taylorotwell I borrowed the name from the circuit breaker pattern but I think |
OK. I have renamed it to public function middleware()
{
return [
(new ThrottlesExceptions(5, 1))->when(fn ($e) => $e instanceof SomeException),
];
} |
It's fairly common to have HTTP calls to third party services in queued jobs. However, some third party services cannot be relied on and may be unstable.
This PR adds a circuit breaker job middleware for such use cases. Once the failures (job exceptions) reach a certain threshold, the circuit breaker trips (circuit opens) and all further calls are delayed until a certain time interval lapses.
To use this job middleware:
By default, failed jobs (that don't exceed the threshold) are retried immediately (with an option to specify a delay) and the key for the rate limiter is the class name (with an option to override this to share a key between jobs that may be using the same service).
If this PR is accepted, I'll follow this up with another PR to implement this for Redis using the
DurationLimiter
.