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