Skip to content
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

[11.x] Add queue job debouncing #50477

Closed
wants to merge 10 commits into from
Closed

Conversation

nandi95
Copy link
Contributor

@nandi95 nandi95 commented Mar 12, 2024

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: #43946
Rebased to 11.x branch as per request on #50347

Copy link

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.

@jameshulse
Copy link
Contributor

This does look useful, but couldn't it just be a package that provides the middleware?

@nandi95
Copy link
Contributor Author

nandi95 commented Mar 13, 2024

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?

@driesvints
Copy link
Member

@nandi95 are you still fixing theses tests? Otherwise best if you resend this when they pass.

@nandi95
Copy link
Contributor Author

nandi95 commented Mar 14, 2024

They gonna take a while, yes. I can resend later. The intention was to generate discussion and get feedback.

@nandi95 nandi95 closed this Mar 14, 2024
@nandi95
Copy link
Contributor Author

nandi95 commented Mar 22, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants