From 2c4d64cd20534bf1cf57fc76cda55ad15f501575 Mon Sep 17 00:00:00 2001 From: IanM <16573496+imorland@users.noreply.github.com> Date: Sun, 29 Sep 2024 15:35:29 +0100 Subject: [PATCH] [1.x] [extensibility] feat: allow classes that extends `AbstractJob` to be placed on a specified queue (#4026) * feat: allow classes that extends AbstractJob to be placed on a specific queue * Apply fixes from StyleCI * php 7.3 compat * Apply fixes from StyleCI * change to to avoid conflicts with extensions that already do this * chore: add docblock explaining that this solution only works for Redis queues * Apply fixes from StyleCI * chore: update docblock * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot --- .../src/Job/SendMentionsNotificationsJob.php | 2 ++ .../src/Job/ComposerCommandJob.php | 2 ++ .../pusher/src/SendPusherNotificationsJob.php | 2 ++ framework/core/src/Mail/Job/SendRawEmailJob.php | 2 ++ .../Job/SendEmailNotificationJob.php | 2 ++ .../Notification/Job/SendNotificationsJob.php | 2 ++ framework/core/src/Queue/AbstractJob.php | 16 ++++++++++++++++ .../src/User/Job/RequestPasswordResetJob.php | 2 ++ 8 files changed, 30 insertions(+) diff --git a/extensions/mentions/src/Job/SendMentionsNotificationsJob.php b/extensions/mentions/src/Job/SendMentionsNotificationsJob.php index f3ed2d7b09..9fea2e5492 100644 --- a/extensions/mentions/src/Job/SendMentionsNotificationsJob.php +++ b/extensions/mentions/src/Job/SendMentionsNotificationsJob.php @@ -47,6 +47,8 @@ class SendMentionsNotificationsJob extends AbstractJob public function __construct(CommentPost $post, array $userMentions, array $postMentions, array $groupMentions) { + parent::__construct(); + $this->post = $post; $this->userMentions = $userMentions; $this->postMentions = $postMentions; diff --git a/extensions/package-manager/src/Job/ComposerCommandJob.php b/extensions/package-manager/src/Job/ComposerCommandJob.php index 8cd4900180..8b30a45bb9 100644 --- a/extensions/package-manager/src/Job/ComposerCommandJob.php +++ b/extensions/package-manager/src/Job/ComposerCommandJob.php @@ -32,6 +32,8 @@ class ComposerCommandJob extends AbstractJob implements ShouldBeUnique public function __construct(AbstractActionCommand $command, string $phpVersion) { + parent::__construct(); + $this->command = $command; $this->phpVersion = $phpVersion; } diff --git a/extensions/pusher/src/SendPusherNotificationsJob.php b/extensions/pusher/src/SendPusherNotificationsJob.php index def83ca28f..00187c17a1 100644 --- a/extensions/pusher/src/SendPusherNotificationsJob.php +++ b/extensions/pusher/src/SendPusherNotificationsJob.php @@ -28,6 +28,8 @@ class SendPusherNotificationsJob extends AbstractJob public function __construct(BlueprintInterface $blueprint, array $recipients) { + parent::__construct(); + $this->blueprint = $blueprint; $this->recipients = $recipients; } diff --git a/framework/core/src/Mail/Job/SendRawEmailJob.php b/framework/core/src/Mail/Job/SendRawEmailJob.php index 9eebc35e68..1ea13666c5 100644 --- a/framework/core/src/Mail/Job/SendRawEmailJob.php +++ b/framework/core/src/Mail/Job/SendRawEmailJob.php @@ -21,6 +21,8 @@ class SendRawEmailJob extends AbstractJob public function __construct(string $email, string $subject, string $body) { + parent::__construct(); + $this->email = $email; $this->subject = $subject; $this->body = $body; diff --git a/framework/core/src/Notification/Job/SendEmailNotificationJob.php b/framework/core/src/Notification/Job/SendEmailNotificationJob.php index 68bffeb17f..44708dd679 100644 --- a/framework/core/src/Notification/Job/SendEmailNotificationJob.php +++ b/framework/core/src/Notification/Job/SendEmailNotificationJob.php @@ -28,6 +28,8 @@ class SendEmailNotificationJob extends AbstractJob public function __construct(MailableInterface $blueprint, User $recipient) { + parent::__construct(); + $this->blueprint = $blueprint; $this->recipient = $recipient; } diff --git a/framework/core/src/Notification/Job/SendNotificationsJob.php b/framework/core/src/Notification/Job/SendNotificationsJob.php index f33fda7afa..6b93013a02 100644 --- a/framework/core/src/Notification/Job/SendNotificationsJob.php +++ b/framework/core/src/Notification/Job/SendNotificationsJob.php @@ -28,6 +28,8 @@ class SendNotificationsJob extends AbstractJob public function __construct(BlueprintInterface $blueprint, array $recipients = []) { + parent::__construct(); + $this->blueprint = $blueprint; $this->recipients = $recipients; } diff --git a/framework/core/src/Queue/AbstractJob.php b/framework/core/src/Queue/AbstractJob.php index 6ec8235a8c..2b2dcc1508 100644 --- a/framework/core/src/Queue/AbstractJob.php +++ b/framework/core/src/Queue/AbstractJob.php @@ -19,4 +19,20 @@ class AbstractJob implements ShouldQueue use InteractsWithQueue; use Queueable; use SerializesModels; + + /** + * The name of the queue on which the job should be placed. + * + * This is only effective on jobs that extend `\Flarum\Queue\AbstractJob` and dispatched via Redis. + * + * @var string|null + */ + public static $sendOnQueue = null; + + public function __construct() + { + if (static::$sendOnQueue) { + $this->onQueue(static::$sendOnQueue); + } + } } diff --git a/framework/core/src/User/Job/RequestPasswordResetJob.php b/framework/core/src/User/Job/RequestPasswordResetJob.php index 5399532d75..9eee178d77 100644 --- a/framework/core/src/User/Job/RequestPasswordResetJob.php +++ b/framework/core/src/User/Job/RequestPasswordResetJob.php @@ -27,6 +27,8 @@ class RequestPasswordResetJob extends AbstractJob public function __construct(string $email) { + parent::__construct(); + $this->email = $email; }