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

[POC] [5.6] Allow chaining multiple queue jobs #20281

Closed

Conversation

JosephSilber
Copy link
Member

The code here is a (fully functional) proof of concept, so it's not fully fleshed out and has no tests.


To test, run php artisan queue:chain-table to publish the queue chain table migration. Then run php artisan migrate to actually create the table. Now you're ready to start chaining like a boss 😎


Allows you to chain a job after multiple jobs run in parallel. For example:

dispatch([new SomeJob(1), new SomeJob(2), new SomeJob(3)])->chain(
    new RunsAfterOthersHaveCompleted(),
);

All 3 SomeJobs will run in parallel. When they're done, the final one will run.


You can construct these chains as complex as you need them to be. At each step, you can have as many parallel jobs as needed. Here's another example:

dispatch([new SomeJob(1), new SomeJob(2)])->chain(
    [new SomeOtherJob(1), new SomeOtherJob(2)],
    [new YetAnotherJob(1), new YetAnotherJob(2)]
);

The SomeJobs will run in parallel. When done, the SomeOtherJobs will run in parallel. Finally, all YetAnotherJobs will run in parallel.

If you're familiar with JS promises, the above is similar to this:

Promise.all([someJob(1), someJob(2)])
       .then(() => Promise.all([someOtherJob(1), someOtherJob(2)]))
       .then(() => Promise.all([yetAnotherJob(1), yetAnotherJob(2)]));

This PR is a resubmission of #19515, with the race condition fixed.

@GrahamCampbell GrahamCampbell changed the title [POC][5.5] Allow chaining multiple queue jobs [POC] [5.6] Allow chaining multiple queue jobs Aug 30, 2017
@Miguel-Serejo
Copy link

dispatch([new SomeJob(1), new SomeJob(2)])->chain(
   [new SomeOtherJob(1), new SomeOtherJob(2)],
   [new YetAnotherJob(1), new YetAnotherJob(2)]
);

Would it make more sense to chain calls to ->chain()?

dispatch([new SomeJob(1), new SomeJob(2)])->chain(
    [new SomeOtherJob(1), new SomeOtherJob(2)])->chain(
    [new YetAnotherJob(1), new YetAnotherJob(2)]
);

@Artistan
Copy link
Contributor

chaining calls to ->chain() would be more synonymous with the JS Promise example that you referenced....

@taylorotwell
Copy link
Member

Holding off on this for now.

@JosephSilber JosephSilber deleted the queue-chaining-no-race branch January 23, 2022 19:05
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.

4 participants