[13.x] Introduce Bus::bulk()#60297
Merged
Merged
Conversation
|
Thanks for submitting a PR! Note that draft PRs 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. |
Contributor
It would be nice to even have a shorthand like this when one doesn't need any imperative logic at all: Bus::dispatchBulk(ProcessUser::class, $users); |
Contributor
Author
|
@shaedrich Seems like a good idea, will leave it for a follow up PR, as don't wanna overcomplicate it just incase 👍🏻 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tip
This is purely for the most optimized way of getting jobs into a queue, it does not check for uniqueness, debounce etc.. ie the same as Bus::batch, but without the increment.
When you need to dispatch multiple jobs at once, ie when a user has done a mass import, export etc.. the only option today (at least to my knowledge 🌚) is:
dispatch()Bus::batch,Queue::bulk(if you know the internals)Having to squeeze every bit of resources I can, one thing I've noticed is:
dispatch()in a foreach is very resource intensive on the driver, as its 1x insert, if you have a lot of other operations going on (jobs etc) .. do this 80k times it adds upBus::batchis great if we care about the tracking of the batch/jobs, but it also writes to the database on every job completion to track progress meaning 1x insert so similar to the above tbhSo, to counter this currently we end up doing something like (I have done this, Im sorry):
The Queue::bulk way above works, but it doesn't feel the best as we have to handle different queues, etc and the signature seems a bit odd.
All we want to do is basically put the jobs on the queue in the most efficient way possible, if they fail that's fine they'll go to failed_jobs.
SO this PR adds
Bus::bulkto just let us do:The method groups by queues and connections automatically, so you dont have to handle it in userland, with the added efficiency of calling bulk() underneath and a nicer DX.
This is extremely useful as it avoids the one dispatch per job and is completely safe cause the
bulkmethod is needed by the Queue interface 😎This is the same as Bus::batch in the sense it just sends the jobs to the queue, just without the incrementing.
This made sense in my head rather than adding a flag like withoutIncrementing() on Bus::batch, but open to your guidance as I'm just shootin my shot to try make this more obvious, feel free to adjust 🫡