From 9fdcc6490693154c0a9d5d0a3abfa68d7ae58465 Mon Sep 17 00:00:00 2001 From: Jack Bayliss Date: Mon, 1 Dec 2025 18:12:13 +0000 Subject: [PATCH 1/3] add runtime exception queue commands for pause,restart and resume commands --- src/Illuminate/Queue/Console/PauseCommand.php | 6 ++++++ src/Illuminate/Queue/Console/RestartCommand.php | 6 ++++++ src/Illuminate/Queue/Console/ResumeCommand.php | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/src/Illuminate/Queue/Console/PauseCommand.php b/src/Illuminate/Queue/Console/PauseCommand.php index 8b18c23ee621..bff9db608c0d 100644 --- a/src/Illuminate/Queue/Console/PauseCommand.php +++ b/src/Illuminate/Queue/Console/PauseCommand.php @@ -5,6 +5,8 @@ use Illuminate\Console\Command; use Illuminate\Contracts\Queue\Factory as QueueManager; use Illuminate\Queue\Console\Concerns\ParsesQueue; +use Illuminate\Queue\Worker; +use RuntimeException; use Symfony\Component\Console\Attribute\AsCommand; #[AsCommand(name: 'queue:pause')] @@ -33,6 +35,10 @@ class PauseCommand extends Command */ public function handle(QueueManager $manager) { + if (! Worker::$pausable) { + throw new RuntimeException('Worker::$pausable must be set to true to use this command.'); + } + [$connection, $queue] = $this->parseQueue($this->argument('queue')); $manager->pause($connection, $queue); diff --git a/src/Illuminate/Queue/Console/RestartCommand.php b/src/Illuminate/Queue/Console/RestartCommand.php index 892380682528..989b4629510b 100644 --- a/src/Illuminate/Queue/Console/RestartCommand.php +++ b/src/Illuminate/Queue/Console/RestartCommand.php @@ -4,7 +4,9 @@ use Illuminate\Console\Command; use Illuminate\Contracts\Cache\Repository as Cache; +use Illuminate\Queue\Worker; use Illuminate\Support\InteractsWithTime; +use RuntimeException; use Symfony\Component\Console\Attribute\AsCommand; #[AsCommand(name: 'queue:restart')] @@ -52,6 +54,10 @@ public function __construct(Cache $cache) */ public function handle() { + if (! Worker::$restartable) { + throw new RuntimeException('Worker::$restartable must be set to true to use this command.'); + } + $this->cache->forever('illuminate:queue:restart', $this->currentTime()); $this->components->info('Broadcasting queue restart signal.'); diff --git a/src/Illuminate/Queue/Console/ResumeCommand.php b/src/Illuminate/Queue/Console/ResumeCommand.php index 67a0ac69293b..77ca217a9d06 100644 --- a/src/Illuminate/Queue/Console/ResumeCommand.php +++ b/src/Illuminate/Queue/Console/ResumeCommand.php @@ -5,6 +5,8 @@ use Illuminate\Console\Command; use Illuminate\Contracts\Queue\Factory as QueueManager; use Illuminate\Queue\Console\Concerns\ParsesQueue; +use Illuminate\Queue\Worker; +use RuntimeException; use Symfony\Component\Console\Attribute\AsCommand; #[AsCommand(name: 'queue:resume', aliases: ['queue:continue'])] @@ -40,6 +42,10 @@ class ResumeCommand extends Command */ public function handle(QueueManager $manager) { + if (! Worker::$pausable) { + throw new RuntimeException('Worker::$pausable must be set to true to use this command.'); + } + [$connection, $queue] = $this->parseQueue($this->argument('queue')); $manager->resume($connection, $queue); From 7d62993df4885393a6e721a8a9b2d76813381e54 Mon Sep 17 00:00:00 2001 From: Jack Bayliss Date: Mon, 1 Dec 2025 18:26:43 +0000 Subject: [PATCH 2/3] message over exception --- src/Illuminate/Queue/Console/PauseCommand.php | 5 +++-- src/Illuminate/Queue/Console/RestartCommand.php | 5 +++-- src/Illuminate/Queue/Console/ResumeCommand.php | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Queue/Console/PauseCommand.php b/src/Illuminate/Queue/Console/PauseCommand.php index bff9db608c0d..ae264f01367c 100644 --- a/src/Illuminate/Queue/Console/PauseCommand.php +++ b/src/Illuminate/Queue/Console/PauseCommand.php @@ -6,7 +6,6 @@ use Illuminate\Contracts\Queue\Factory as QueueManager; use Illuminate\Queue\Console\Concerns\ParsesQueue; use Illuminate\Queue\Worker; -use RuntimeException; use Symfony\Component\Console\Attribute\AsCommand; #[AsCommand(name: 'queue:pause')] @@ -36,7 +35,9 @@ class PauseCommand extends Command public function handle(QueueManager $manager) { if (! Worker::$pausable) { - throw new RuntimeException('Worker::$pausable must be set to true to use this command.'); + $this->components->error('Worker::$pausable must be set to true to use this command.'); + + return 1; } [$connection, $queue] = $this->parseQueue($this->argument('queue')); diff --git a/src/Illuminate/Queue/Console/RestartCommand.php b/src/Illuminate/Queue/Console/RestartCommand.php index 989b4629510b..c1f458db6f06 100644 --- a/src/Illuminate/Queue/Console/RestartCommand.php +++ b/src/Illuminate/Queue/Console/RestartCommand.php @@ -6,7 +6,6 @@ use Illuminate\Contracts\Cache\Repository as Cache; use Illuminate\Queue\Worker; use Illuminate\Support\InteractsWithTime; -use RuntimeException; use Symfony\Component\Console\Attribute\AsCommand; #[AsCommand(name: 'queue:restart')] @@ -55,7 +54,9 @@ public function __construct(Cache $cache) public function handle() { if (! Worker::$restartable) { - throw new RuntimeException('Worker::$restartable must be set to true to use this command.'); + $this->components->error('Worker::$restartable must be set to true to use this command.'); + + return; } $this->cache->forever('illuminate:queue:restart', $this->currentTime()); diff --git a/src/Illuminate/Queue/Console/ResumeCommand.php b/src/Illuminate/Queue/Console/ResumeCommand.php index 77ca217a9d06..48b1f7d1a00a 100644 --- a/src/Illuminate/Queue/Console/ResumeCommand.php +++ b/src/Illuminate/Queue/Console/ResumeCommand.php @@ -6,7 +6,6 @@ use Illuminate\Contracts\Queue\Factory as QueueManager; use Illuminate\Queue\Console\Concerns\ParsesQueue; use Illuminate\Queue\Worker; -use RuntimeException; use Symfony\Component\Console\Attribute\AsCommand; #[AsCommand(name: 'queue:resume', aliases: ['queue:continue'])] @@ -43,7 +42,9 @@ class ResumeCommand extends Command public function handle(QueueManager $manager) { if (! Worker::$pausable) { - throw new RuntimeException('Worker::$pausable must be set to true to use this command.'); + $this->components->error('Worker::$pausable must be set to true to use this command.'); + + return 1; } [$connection, $queue] = $this->parseQueue($this->argument('queue')); From 89e376bc034e2b23b58ebc704b261c4699f99f2d Mon Sep 17 00:00:00 2001 From: Jack Bayliss Date: Mon, 1 Dec 2025 18:33:52 +0000 Subject: [PATCH 3/3] add faliure / success to restart command --- src/Illuminate/Queue/Console/RestartCommand.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Queue/Console/RestartCommand.php b/src/Illuminate/Queue/Console/RestartCommand.php index c1f458db6f06..79667b274a3a 100644 --- a/src/Illuminate/Queue/Console/RestartCommand.php +++ b/src/Illuminate/Queue/Console/RestartCommand.php @@ -49,18 +49,20 @@ public function __construct(Cache $cache) /** * Execute the console command. * - * @return void + * @return int */ public function handle() { if (! Worker::$restartable) { $this->components->error('Worker::$restartable must be set to true to use this command.'); - return; + return self::FAILURE; } $this->cache->forever('illuminate:queue:restart', $this->currentTime()); $this->components->info('Broadcasting queue restart signal.'); + + return self::SUCCESS; } }