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] Ensure that events are fired when bulk dispatching jobs onto the database queue #54658

Closed
wants to merge 1 commit into from

Conversation

lukasmu
Copy link

@lukasmu lukasmu commented Feb 17, 2025

Fixes #52689 by removing the custom bulk method from the DatabaseQueue class. The default implementation of the bulk method from the abstract Queue class will now be used.

Benefits:

  1. The JobQueueing and JobQueued events are now fired as expected when bulk dispatching jobs onto the database queue (as elaborated upon in Bulk dispatching jobs onto the DatabaseQueue does not trigger jobs #52689).
  2. The logic in the enqueueUsing method is no longer bypassed when bulk dispatching jobs.
  3. The DatabaseQueue class has fewer lines of code now.

Drawback:

  1. Bulk dispatching jobs may be less performant than before, as multiple database inserts are required. However, performance can still be improved by wrapping the bulk method in a transaction if needed.

In my opinion, the benefits clearly outweigh the drawback. Consistency is more important than performance in this case, and performance can still be optimized by wrapping the bulk method in a transaction when necessary.

One unit test was slightly modified to accommodate this change, and an integration test was added.

@taylorotwell
Copy link
Member

A breaking change to make this multiple queries imo.

@lukasmu
Copy link
Author

lukasmu commented Feb 17, 2025

@taylorotwell: Would you still consider it a breaking change if we manage to wrap the queries into a single transaction? Or would you be open to merge this into another (future) major Laravel release?

I've been experimenting extensively with fixing #52689 without splitting the insert statement, but it's not trivial. The main issue is that we can't easily retrieve the IDs of the newly inserted rows from the jobs table, which are necessary to dispatch the JobQueued events.

I've put together a proof of concept here: 11.x...lukasmu:framework:fixes-52689-variation

Thanks for your consideration!

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.

Bulk dispatching jobs onto the DatabaseQueue does not trigger jobs
2 participants