[2.x] feat(queue): restore per-class queue routing on AbstractJob - #4656
Merged
Conversation
Reintroduces the `$onQueue` static property + constructor that 1.x jobs relied on for per-class queue routing. Without this, operators have no built-in way to send a specific job class to a dedicated queue without patching every dispatch site, which is why multiple 2.x-compatible extensions (`FoF\GeoIP\Jobs\RetrieveIP`, `Flarum\Gdpr\Jobs\GdprJob`) have already re-implemented the same hook in their own base classes. Property name follows the convention those extensions settled on (`$onQueue` rather than 1.x's `$sendOnQueue`). Closes #4653
…truct Adds `parent::__construct()` to every existing job in core and the monorepo extensions so that operators can route any of them via the `$onQueue` static property without having to subclass. Also removes the now-redundant local `$onQueue` shadow from `Flarum\Gdpr\Jobs\GdprJob` and the workaround constructor from `Flarum\Realtime\Push\Jobs\Job` — both are now provided by the base class. If we're restoring the convention, the standard library should lead by example: every shipped job should be routable.
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.
Summary
Restores the
$onQueuestatic property + constructor that 1.x'sAbstractJobexposed, and wires every in-tree job through it so operators can route any shipped job onto a dedicated queue without subclassing.Without this, there's no built-in way for an operator (or an extension) to dispatch all instances of a given job class onto a dedicated queue without patching every dispatch site. Multiple 2.x-compatible extensions have already re-implemented this hook themselves — see issue #4653 for examples from
FoF\GeoIP\Jobs\RetrieveIPandFlarum\Gdpr\Jobs\GdprJob. Both have settled on the name$onQueue(rather than 1.x's$sendOnQueue), so this PR adopts the same name.Changes
Flarum\Queue\AbstractJob(commit 1):public static ?string $onQueue = null;property.__construct()that calls$this->onQueue(static::$onQueue)when the static property is set on the concrete subclass (late-static-bound, so each subclass gets its own routing knob).Every in-tree job that has its own constructor (commit 2) now calls
parent::__construct()so it inherits the routing behavior:Flarum\Notification\Job\SendEmailNotificationJobFlarum\Notification\Job\SendNotificationsJobFlarum\Mail\Job\SendAbandonedExtensionsEmailJobFlarum\Mail\Job\SendInformationalEmailJobFlarum\User\Job\RequestPasswordResetJobFlarum\Search\Job\IndexJobFlarum\Messages\Job\SendMessageNotificationsJobFlarum\Pusher\SendPusherNotificationsJobFlarum\ExtensionManager\Job\ComposerCommandJobFlarum\Mentions\Job\SendMentionsNotificationsJobFlarum\Gdpr\Jobs\ExportJob,ErasureJobCleanups for jobs that previously implemented the hook themselves:
Flarum\Gdpr\Jobs\GdprJob: drop the local$onQueueshadow (inherited now).Flarum\Realtime\Push\Jobs\Job: drop the local$onQueueshadow and the workaround__construct()(inherited now). All concreteSend*Jobsubclasses in the same directory already callparent::__construct(), so routing flows through unchanged.Behavior
AbstractJob::$onQueuedefaults tonull, so default behavior is unchanged.SomeJob::$onQueue = 'queue-name'once at boot to route all instances of that job class onto a specific queue.Child extends Parentsubclass's own$onQueuevalue wins over the parent's, as expected.Test plan
tests/unit/Queue/AbstractJobTest.phpcovers: default behavior (no routing), routing via the static property, and late-static-binding under inheritance.tests/unit/Queue,tests/integration/queue).Closes #4653