[8.x] Use "sync" queue in Bus::dispatchNow() #32559
Merged
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.
This PR fixes two issues. First, it fixes an issue where job middleware are not run when doing something like
ProcessPodcast::dispatchNow()
. This can be fixed by dispatching this job through thesync
queue instead of invoking it directly from the command bus.The second problem it fixes is currently any jobs dispatched using
dispatchNow
do not have have access to the$this->job
property, even though they useInteractsWithQueue
. The$this->job
variable will just benull
. This is awkward because you may have a job that is sometimes dispatched using the normaldispatch
method and sometimes usingdispatchNow
and the$this->job
variable is only going to be available when dispatched usingdispatch
. So, you would have to putnull
checks within your job to work around this. This PR solves this by setting aSyncJob
on the job if one is not already set.Added a new
dispatchDirectly
method to execute a job directly within the command bus without using the sync queue or job middleware (basically the olddispatchNow
behavior).Alternative:
One alternative to this is to leave
dispatchNow
as it is and add a newdispatchSync
method (or some similar name) that dispatches the job using thesync
queue.