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

Bulk dispatching jobs onto the DatabaseQueue does not trigger jobs #52689

Open
lukasmu opened this issue Sep 7, 2024 · 2 comments
Open

Bulk dispatching jobs onto the DatabaseQueue does not trigger jobs #52689

lukasmu opened this issue Sep 7, 2024 · 2 comments

Comments

@lukasmu
Copy link

lukasmu commented Sep 7, 2024

Laravel Version

11.20.0

PHP Version

8.3.9

Database Driver & Version

No response

Description

When pushing an array of jobs onto the database queue using the bulk method the JobQueueing and JobQueued events are not triggered.

In contrast, when pushing an array of jobs onto the redis queue or the SQS queue using the bulk method, these event are triggered (as they should be imho).

I think that @RuslanMelnychenko also described symptoms of this bug in #52380.

I see two potential solutions:

Steps To Reproduce

Add a listener for JobQueueing and dispatch jobs onto different queues:

Bus::batch($jobs)->onConnection('database')->dispatch();
Bus::batch($jobs)->onConnection('redis')->dispatch();

The listener will not be invoked when using the database connection, while it will be invoked for the redis connection.

Copy link

github-actions bot commented Sep 9, 2024

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@ismaildasci
Copy link

Hey! 👋

You’re right—when pushing an array of jobs to the database queue with the bulk method, the JobQueueing and JobQueued events aren’t triggered. This is different from the behavior on Redis or SQS queues, which can definitely cause inconsistencies.
Possible Workaround

One option is to manually trigger these events in your code before and after the bulk dispatch. Here’s a quick example:

use Illuminate\Support\Facades\Event;
use Illuminate\Queue\Events\JobQueueing;
use Illuminate\Queue\Events\JobQueued;

$jobs = [ /* your array of jobs */ ];

foreach ($jobs as $job) {
Event::dispatch(new JobQueueing($job));
}

Bus::batch($jobs)->onConnection('database')->dispatch();

foreach ($jobs as $job) {
Event::dispatch(new JobQueued($job));
}

This will manually raise the JobQueueing and JobQueued events, ensuring consistency across different queue drivers. Hope this helps! 😊

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

No branches or pull requests

3 participants