Skip to content

Commit 7c96808

Browse files
authored
[12.x] Clean up queue pausing (#57863)
* employ trait * employ trait * typehints * use alias * remove reference * typehint
1 parent f050360 commit 7c96808

File tree

5 files changed

+38
-143
lines changed

5 files changed

+38
-143
lines changed

src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
use Illuminate\Notifications\Console\NotificationTableCommand;
9292
use Illuminate\Queue\Console\BatchesTableCommand;
9393
use Illuminate\Queue\Console\ClearCommand as QueueClearCommand;
94-
use Illuminate\Queue\Console\ContinueCommand as QueueContinueCommand;
9594
use Illuminate\Queue\Console\FailedTableCommand;
9695
use Illuminate\Queue\Console\FlushFailedCommand as FlushFailedQueueCommand;
9796
use Illuminate\Queue\Console\ForgetFailedCommand as ForgetFailedQueueCommand;
@@ -148,7 +147,6 @@ class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvid
148147
'PackageDiscover' => PackageDiscoverCommand::class,
149148
'PruneStaleTagsCommand' => PruneStaleTagsCommand::class,
150149
'QueueClear' => QueueClearCommand::class,
151-
'QueueContinue' => QueueContinueCommand::class,
152150
'QueueFailed' => ListFailedQueueCommand::class,
153151
'QueueFlush' => FlushFailedQueueCommand::class,
154152
'QueueForget' => ForgetFailedQueueCommand::class,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Illuminate\Queue\Console\Concerns;
4+
5+
trait ParsesQueue
6+
{
7+
/**
8+
* Parse the queue argument into connection and queue name.
9+
*
10+
* @param string $queue
11+
* @return array{string, string}
12+
*/
13+
protected function parseQueue($queue)
14+
{
15+
[$connection, $queue] = array_pad(explode(':', $queue, 2), 2, null);
16+
17+
return isset($queue)
18+
? [$connection, $queue]
19+
: [$this->laravel['config']['queue.default'], $connection];
20+
}
21+
}

src/Illuminate/Queue/Console/ContinueCommand.php

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/Illuminate/Queue/Console/PauseCommand.php

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Contracts\Queue\Factory as QueueManager;
7+
use Illuminate\Queue\Console\Concerns\ParsesQueue;
78
use Symfony\Component\Console\Attribute\AsCommand;
89

910
#[AsCommand(name: 'queue:pause')]
1011
class PauseCommand extends Command
1112
{
13+
use ParsesQueue;
14+
1215
/**
1316
* The console command name.
1417
*
@@ -23,51 +26,19 @@ class PauseCommand extends Command
2326
*/
2427
protected $description = 'Pause job processing for a specific queue';
2528

26-
/**
27-
* The queue manager instance.
28-
*
29-
* @var \Illuminate\Contracts\Queue\Factory
30-
*/
31-
protected $manager;
32-
33-
/**
34-
* Create a new queue pause command.
35-
*/
36-
public function __construct(QueueManager $manager)
37-
{
38-
parent::__construct();
39-
40-
$this->manager = $manager;
41-
}
42-
4329
/**
4430
* Execute the console command.
4531
*
4632
* @return int
4733
*/
48-
public function handle()
34+
public function handle(QueueManager $manager)
4935
{
5036
[$connection, $queue] = $this->parseQueue($this->argument('queue'));
5137

52-
$this->manager->pause($connection, $queue);
38+
$manager->pause($connection, $queue);
5339

5440
$this->components->info("Job processing on queue [{$connection}:{$queue}] has been paused.");
5541

5642
return 0;
5743
}
58-
59-
/**
60-
* Parse the queue argument into the connection and queue name.
61-
*
62-
* @param string $queue
63-
* @return array
64-
*/
65-
protected function parseQueue($queue)
66-
{
67-
[$connection, $queue] = array_pad(explode(':', $queue, 2), 2, null);
68-
69-
return isset($queue)
70-
? [$connection, $queue]
71-
: [$this->laravel['config']['queue.default'], $connection];
72-
}
7344
}

src/Illuminate/Queue/Console/ResumeCommand.php

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Contracts\Queue\Factory as QueueManager;
7+
use Illuminate\Queue\Console\Concerns\ParsesQueue;
78
use Symfony\Component\Console\Attribute\AsCommand;
89

9-
#[AsCommand(name: 'queue:resume')]
10+
#[AsCommand(name: 'queue:resume', aliases: ['queue:continue'])]
1011
class ResumeCommand extends Command
1112
{
13+
use ParsesQueue;
14+
1215
/**
1316
* The console command name.
1417
*
@@ -17,57 +20,32 @@ class ResumeCommand extends Command
1720
protected $signature = 'queue:resume {queue : The name of the queue that should resume processing}';
1821

1922
/**
20-
* The console command description.
23+
* The console command name aliases.
2124
*
22-
* @var string
25+
* @var list<string>
2326
*/
24-
protected $description = 'Resume job processing for a paused queue';
27+
protected $aliases = ['queue:continue'];
2528

2629
/**
27-
* The queue manager instance.
30+
* The console command description.
2831
*
29-
* @var \Illuminate\Contracts\Queue\Factory
30-
*/
31-
protected $manager;
32-
33-
/**
34-
* Create a new queue resume command.
32+
* @var string
3533
*/
36-
public function __construct(QueueManager $manager)
37-
{
38-
parent::__construct();
39-
40-
$this->manager = $manager;
41-
}
34+
protected $description = 'Resume job processing for a paused queue';
4235

4336
/**
4437
* Execute the console command.
4538
*
4639
* @return int
4740
*/
48-
public function handle()
41+
public function handle(QueueManager $manager)
4942
{
5043
[$connection, $queue] = $this->parseQueue($this->argument('queue'));
5144

52-
$this->manager->resume($connection, $queue);
45+
$manager->resume($connection, $queue);
5346

5447
$this->components->info("Job processing on queue [{$connection}:{$queue}] has been resumed.");
5548

5649
return 0;
5750
}
58-
59-
/**
60-
* Parse the queue argument into connection and queue name.
61-
*
62-
* @param string $queue
63-
* @return array
64-
*/
65-
protected function parseQueue($queue)
66-
{
67-
[$connection, $queue] = array_pad(explode(':', $queue, 2), 2, null);
68-
69-
return isset($queue)
70-
? [$connection, $queue]
71-
: [$this->laravel['config']['queue.default'], $connection];
72-
}
7351
}

0 commit comments

Comments
 (0)