From a8b508a64107211b69d46166a7155c97882b9860 Mon Sep 17 00:00:00 2001 From: IanM Date: Thu, 26 Sep 2024 18:51:06 +0100 Subject: [PATCH 1/9] feat: allow classes that extends AbstractJob to be placed on a specific queue --- .../mentions/src/Job/SendMentionsNotificationsJob.php | 2 ++ .../package-manager/src/Job/ComposerCommandJob.php | 2 ++ extensions/pusher/src/SendPusherNotificationsJob.php | 2 ++ framework/core/src/Mail/Job/SendRawEmailJob.php | 2 ++ .../src/Notification/Job/SendEmailNotificationJob.php | 2 ++ .../core/src/Notification/Job/SendNotificationsJob.php | 2 ++ framework/core/src/Queue/AbstractJob.php | 10 ++++++++++ .../core/src/User/Job/RequestPasswordResetJob.php | 2 ++ 8 files changed, 24 insertions(+) diff --git a/extensions/mentions/src/Job/SendMentionsNotificationsJob.php b/extensions/mentions/src/Job/SendMentionsNotificationsJob.php index f3ed2d7b09..e86924de1f 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..b01dda90a6 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..b52b2bbd42 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..d3e76358b6 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..d973c55cf1 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..f6838c39fd 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..bfc4331bb7 100644 --- a/framework/core/src/Queue/AbstractJob.php +++ b/framework/core/src/Queue/AbstractJob.php @@ -19,4 +19,14 @@ class AbstractJob implements ShouldQueue use InteractsWithQueue; use Queueable; use SerializesModels; + + public static ?string $onQueue = null; + + public function __construct() + { + if (static::$onQueue) { + $this->onQueue(static::$onQueue); + } + } + } diff --git a/framework/core/src/User/Job/RequestPasswordResetJob.php b/framework/core/src/User/Job/RequestPasswordResetJob.php index 5399532d75..74f4d2a8d4 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; } From c56dfb7a40f2961eef243a124733e9a17c71f7db Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 26 Sep 2024 17:51:34 +0000 Subject: [PATCH 2/9] Apply fixes from StyleCI --- extensions/mentions/src/Job/SendMentionsNotificationsJob.php | 2 +- extensions/package-manager/src/Job/ComposerCommandJob.php | 2 +- extensions/pusher/src/SendPusherNotificationsJob.php | 2 +- framework/core/src/Mail/Job/SendRawEmailJob.php | 2 +- .../core/src/Notification/Job/SendEmailNotificationJob.php | 2 +- framework/core/src/Notification/Job/SendNotificationsJob.php | 2 +- framework/core/src/Queue/AbstractJob.php | 1 - framework/core/src/User/Job/RequestPasswordResetJob.php | 2 +- 8 files changed, 7 insertions(+), 8 deletions(-) diff --git a/extensions/mentions/src/Job/SendMentionsNotificationsJob.php b/extensions/mentions/src/Job/SendMentionsNotificationsJob.php index e86924de1f..9fea2e5492 100644 --- a/extensions/mentions/src/Job/SendMentionsNotificationsJob.php +++ b/extensions/mentions/src/Job/SendMentionsNotificationsJob.php @@ -48,7 +48,7 @@ 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 b01dda90a6..8b30a45bb9 100644 --- a/extensions/package-manager/src/Job/ComposerCommandJob.php +++ b/extensions/package-manager/src/Job/ComposerCommandJob.php @@ -33,7 +33,7 @@ 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 b52b2bbd42..00187c17a1 100644 --- a/extensions/pusher/src/SendPusherNotificationsJob.php +++ b/extensions/pusher/src/SendPusherNotificationsJob.php @@ -29,7 +29,7 @@ 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 d3e76358b6..1ea13666c5 100644 --- a/framework/core/src/Mail/Job/SendRawEmailJob.php +++ b/framework/core/src/Mail/Job/SendRawEmailJob.php @@ -22,7 +22,7 @@ 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 d973c55cf1..44708dd679 100644 --- a/framework/core/src/Notification/Job/SendEmailNotificationJob.php +++ b/framework/core/src/Notification/Job/SendEmailNotificationJob.php @@ -29,7 +29,7 @@ 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 f6838c39fd..6b93013a02 100644 --- a/framework/core/src/Notification/Job/SendNotificationsJob.php +++ b/framework/core/src/Notification/Job/SendNotificationsJob.php @@ -29,7 +29,7 @@ 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 bfc4331bb7..d9adba17e4 100644 --- a/framework/core/src/Queue/AbstractJob.php +++ b/framework/core/src/Queue/AbstractJob.php @@ -28,5 +28,4 @@ public function __construct() $this->onQueue(static::$onQueue); } } - } diff --git a/framework/core/src/User/Job/RequestPasswordResetJob.php b/framework/core/src/User/Job/RequestPasswordResetJob.php index 74f4d2a8d4..9eee178d77 100644 --- a/framework/core/src/User/Job/RequestPasswordResetJob.php +++ b/framework/core/src/User/Job/RequestPasswordResetJob.php @@ -28,7 +28,7 @@ class RequestPasswordResetJob extends AbstractJob public function __construct(string $email) { parent::__construct(); - + $this->email = $email; } From 8b06df88f2a7dbd8f4d492b6fcc4c7b28fc6ded8 Mon Sep 17 00:00:00 2001 From: IanM Date: Fri, 27 Sep 2024 07:39:10 +0100 Subject: [PATCH 3/9] php 7.3 compat --- framework/core/src/Queue/AbstractJob.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/core/src/Queue/AbstractJob.php b/framework/core/src/Queue/AbstractJob.php index d9adba17e4..a67b736abb 100644 --- a/framework/core/src/Queue/AbstractJob.php +++ b/framework/core/src/Queue/AbstractJob.php @@ -20,7 +20,10 @@ class AbstractJob implements ShouldQueue use Queueable; use SerializesModels; - public static ?string $onQueue = null; + /** + * @var string|null + */ + public static $onQueue = null; public function __construct() { From 7a1fa57f9063fa7c3a3d5a4b627bb019604b9d9f Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 27 Sep 2024 06:39:25 +0000 Subject: [PATCH 4/9] Apply fixes from StyleCI --- framework/core/src/Queue/AbstractJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Queue/AbstractJob.php b/framework/core/src/Queue/AbstractJob.php index a67b736abb..2a8ae5c821 100644 --- a/framework/core/src/Queue/AbstractJob.php +++ b/framework/core/src/Queue/AbstractJob.php @@ -23,7 +23,7 @@ class AbstractJob implements ShouldQueue /** * @var string|null */ - public static $onQueue = null; + public static $onQueue = null; public function __construct() { From 58c36a4f4034b6c8ff79aaae05032b283002777c Mon Sep 17 00:00:00 2001 From: IanM Date: Sat, 28 Sep 2024 11:00:56 +0100 Subject: [PATCH 5/9] change to to avoid conflicts with extensions that already do this --- framework/core/src/Queue/AbstractJob.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Queue/AbstractJob.php b/framework/core/src/Queue/AbstractJob.php index 2a8ae5c821..207f3f1b66 100644 --- a/framework/core/src/Queue/AbstractJob.php +++ b/framework/core/src/Queue/AbstractJob.php @@ -23,12 +23,12 @@ class AbstractJob implements ShouldQueue /** * @var string|null */ - public static $onQueue = null; + public static $sendOnQueue = null; public function __construct() { - if (static::$onQueue) { - $this->onQueue(static::$onQueue); + if (static::$sendOnQueue) { + $this->onQueue(static::$sendOnQueue); } } } From ff75c1e18a1d3ad2aebe0775c8ab9ec33e4d53eb Mon Sep 17 00:00:00 2001 From: IanM Date: Sat, 28 Sep 2024 18:30:27 +0100 Subject: [PATCH 6/9] chore: add docblock explaining that this solution only works for Redis queues --- framework/core/src/Queue/AbstractJob.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/framework/core/src/Queue/AbstractJob.php b/framework/core/src/Queue/AbstractJob.php index 207f3f1b66..e7bffe9f39 100644 --- a/framework/core/src/Queue/AbstractJob.php +++ b/framework/core/src/Queue/AbstractJob.php @@ -21,6 +21,10 @@ class AbstractJob implements ShouldQueue use SerializesModels; /** + * The name of the queue on which the job should be placed. + * + * This is only effective on jobs dispatched via Redis. + * * @var string|null */ public static $sendOnQueue = null; From 976b71cb87718c7456065933ba422413df1727a2 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 28 Sep 2024 17:30:42 +0000 Subject: [PATCH 7/9] Apply fixes from StyleCI --- framework/core/src/Queue/AbstractJob.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Queue/AbstractJob.php b/framework/core/src/Queue/AbstractJob.php index e7bffe9f39..1f4e45ba40 100644 --- a/framework/core/src/Queue/AbstractJob.php +++ b/framework/core/src/Queue/AbstractJob.php @@ -22,9 +22,9 @@ class AbstractJob implements ShouldQueue /** * The name of the queue on which the job should be placed. - * + * * This is only effective on jobs dispatched via Redis. - * + * * @var string|null */ public static $sendOnQueue = null; From 4b88477e537ff80cfec5132325e78719e8871017 Mon Sep 17 00:00:00 2001 From: IanM Date: Sun, 29 Sep 2024 07:06:41 +0100 Subject: [PATCH 8/9] chore: update docblock --- framework/core/src/Queue/AbstractJob.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Queue/AbstractJob.php b/framework/core/src/Queue/AbstractJob.php index 1f4e45ba40..2b6d9b6b96 100644 --- a/framework/core/src/Queue/AbstractJob.php +++ b/framework/core/src/Queue/AbstractJob.php @@ -22,9 +22,9 @@ class AbstractJob implements ShouldQueue /** * The name of the queue on which the job should be placed. - * - * This is only effective on jobs dispatched via Redis. - * + * + * This is only effective on jobs that extend `\Flarum\Queue\AbstractJob` and dispatched via Redis. + * * @var string|null */ public static $sendOnQueue = null; From 3711e699d2af64f5862dcf47a8ecd9073dde1782 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 29 Sep 2024 06:07:57 +0000 Subject: [PATCH 9/9] Apply fixes from StyleCI --- framework/core/src/Queue/AbstractJob.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Queue/AbstractJob.php b/framework/core/src/Queue/AbstractJob.php index 2b6d9b6b96..2b2dcc1508 100644 --- a/framework/core/src/Queue/AbstractJob.php +++ b/framework/core/src/Queue/AbstractJob.php @@ -22,9 +22,9 @@ class AbstractJob implements ShouldQueue /** * 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;