[11.x] Add Dispatchable::newPendingDispatch()
#54153
Merged
+16
−5
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 consolidates the creation of a PendingDispatch. It does not however consolidate for the
dispatch()
helper method.Why
Ultimately, what I would like to be able to do is call
TwSync::dispatch($team)
and be able to universally set the queue/connection without having to write it repeatedly. We would just "extend" the Dispatchable trait and modify the newPendingDispatch function so it calls another function on the job before instantiating the PendingDispatch. That would be something like this in userland code:We are essentially creating a post-job instantiation, pre-PendingDispatching hook.
We have Horizon set up with 3 connections and 3-4 queues each, so it's easy to mismatch, and there's a lot of duplicative code in our job constructors where we set the queue/connection. Easy to forget to do and then find out you've been dispatching a job to connection that doesn't handle a particular queue (so the job just sits in queued job purgatory).
Alternate solution
Add a
if method_exists($job, 'prepareForDispatch') { ... }
clause somewhere, not sure if that would be the dispatcher or the PendingDispatch constructor.