framework
framework copied to clipboard
[11.x] Add queue job debouncing
[!NOTE] This is a work-in-progress, I would like some feedback and contributions before spending any more time on this.
I have come across the need for such logic multiple times now, so I'm attempting to add this in a backward compatible way. The goal is to make it work with the existing infrastructure so the user doesn't have to add an extra trait or interface to the jobs, they can just start dispatching with debouncing working.
Why add this?
Sometimes a job might do some heavy computation or talk to an external api; things that the developer might decide is a waste of resources and should only be executed every so often. In this case, a debouncing pattern should be available to prevent spamming the logic path.
Example use-cases:
- send a single email to user when an event happens or when a burst of events happens.
- calculate some statistics after one or more resources changed in quick succession.
- generate a report only once even when the user requests it repeatedly in a short period of time.
Questions/Considerations to discuss:
- Redis count is atomic, what about the rest of the cache drivers?
- How should sync driver handle this?
- Any possible issues with batches and chained batches?
- How could this be effectively tested?
- Anything else?
Previous discussion: https://github.com/laravel/framework/discussions/43946 Rebased to 11.x branch as per request on https://github.com/laravel/framework/pull/50347
Thanks for submitting a PR!
Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.
Pull requests that are abandoned in draft may be closed due to inactivity.
This does look useful, but couldn't it just be a package that provides the middleware?
This does look useful, but couldn't it just be a package that provides the middleware?
It could be. I think. It would mean that the user needs to add some code for the package to work. Why would you prefer it as a package?
@nandi95 are you still fixing theses tests? Otherwise best if you resend this when they pass.
They gonna take a while, yes. I can resend later. The intention was to generate discussion and get feedback.
@nandi95 are you still fixing theses tests? Otherwise best if you resend this when they pass.
Got the tests passing. Should I reopen this PR now? I still need to add lots of tests of my own but wary of doing lots of work if we know it's going to get rejected. @driesvints