[11.x] Introduce OnQueue
and OnConnection
attributes for jobs
#54229
+221
−0
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.
The problem
PHP is weird about traits. If a class uses a trait, then it cannot re-declare properties from the trait with differing values. (Though if another class uses the trait and then you extend that class, you can 🙃)
This is problematic with setting queue/connections, where it would be great if we could just define the
$queue
and$connection
properties.An example with Queueable
Setting queue/connection is annoying
My jobs do not need to be dynamic in where they are dispatched. If it's a SyncAthletesJob, it's always on the import queue (and the import queue is always on the redis_medium connection, but that's not a problem solved here).
The two not-so-pretty ways of specifying this
The solution
Introduce
OnQueue
andOnConnection
attributes.Now the above job can look clean 🧹 and I never have to worry about specifying queue/connection in calling code or inside of the constructor.
Bonus: when I call
dispatch(new SyncAthletesJob($teamId))
I get the same benefit.Follow ups
Does this need added for queued event listeners as well? If so, we could share these attributes, but leaving them in Foundation/Bus doesn't really make sense.
Additional attributes for
#[OnDasher]
,#[OnDancer]
,#[OnPrancer]
,#[OnVixen]
, et cetera