Skip to content

Commit 2c4d64c

Browse files
imorlandStyleCIBot
andauthored
[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 <bot@styleci.io>
1 parent c9bd7da commit 2c4d64c

File tree

8 files changed

+30
-0
lines changed

8 files changed

+30
-0
lines changed

extensions/mentions/src/Job/SendMentionsNotificationsJob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class SendMentionsNotificationsJob extends AbstractJob
4747

4848
public function __construct(CommentPost $post, array $userMentions, array $postMentions, array $groupMentions)
4949
{
50+
parent::__construct();
51+
5052
$this->post = $post;
5153
$this->userMentions = $userMentions;
5254
$this->postMentions = $postMentions;

extensions/package-manager/src/Job/ComposerCommandJob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class ComposerCommandJob extends AbstractJob implements ShouldBeUnique
3232

3333
public function __construct(AbstractActionCommand $command, string $phpVersion)
3434
{
35+
parent::__construct();
36+
3537
$this->command = $command;
3638
$this->phpVersion = $phpVersion;
3739
}

extensions/pusher/src/SendPusherNotificationsJob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class SendPusherNotificationsJob extends AbstractJob
2828

2929
public function __construct(BlueprintInterface $blueprint, array $recipients)
3030
{
31+
parent::__construct();
32+
3133
$this->blueprint = $blueprint;
3234
$this->recipients = $recipients;
3335
}

framework/core/src/Mail/Job/SendRawEmailJob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class SendRawEmailJob extends AbstractJob
2121

2222
public function __construct(string $email, string $subject, string $body)
2323
{
24+
parent::__construct();
25+
2426
$this->email = $email;
2527
$this->subject = $subject;
2628
$this->body = $body;

framework/core/src/Notification/Job/SendEmailNotificationJob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class SendEmailNotificationJob extends AbstractJob
2828

2929
public function __construct(MailableInterface $blueprint, User $recipient)
3030
{
31+
parent::__construct();
32+
3133
$this->blueprint = $blueprint;
3234
$this->recipient = $recipient;
3335
}

framework/core/src/Notification/Job/SendNotificationsJob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class SendNotificationsJob extends AbstractJob
2828

2929
public function __construct(BlueprintInterface $blueprint, array $recipients = [])
3030
{
31+
parent::__construct();
32+
3133
$this->blueprint = $blueprint;
3234
$this->recipients = $recipients;
3335
}

framework/core/src/Queue/AbstractJob.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,20 @@ class AbstractJob implements ShouldQueue
1919
use InteractsWithQueue;
2020
use Queueable;
2121
use SerializesModels;
22+
23+
/**
24+
* The name of the queue on which the job should be placed.
25+
*
26+
* This is only effective on jobs that extend `\Flarum\Queue\AbstractJob` and dispatched via Redis.
27+
*
28+
* @var string|null
29+
*/
30+
public static $sendOnQueue = null;
31+
32+
public function __construct()
33+
{
34+
if (static::$sendOnQueue) {
35+
$this->onQueue(static::$sendOnQueue);
36+
}
37+
}
2238
}

framework/core/src/User/Job/RequestPasswordResetJob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class RequestPasswordResetJob extends AbstractJob
2727

2828
public function __construct(string $email)
2929
{
30+
parent::__construct();
31+
3032
$this->email = $email;
3133
}
3234

0 commit comments

Comments
 (0)