From 55e418226cdaada2f2ef25edff1489a7302d67d0 Mon Sep 17 00:00:00 2001 From: Mark de Heij Date: Fri, 22 Nov 2024 14:22:50 +0100 Subject: [PATCH] Add Clear Queues Command (#5) Add clear-queues console command --------- Co-authored-by: Mark de Heij Co-authored-by: Sander Beenen --- Plugin.php | 2 ++ console/ClearQueuesCommand.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 console/ClearQueuesCommand.php diff --git a/Plugin.php b/Plugin.php index 964a1f7..0a2b3f3 100644 --- a/Plugin.php +++ b/Plugin.php @@ -10,6 +10,7 @@ use Illuminate\Notifications\NotificationServiceProvider; use Laravel\Horizon\Horizon; use System\Classes\PluginBase; +use Vdlp\Horizon\Console\ClearQueuesCommand; use Vdlp\Horizon\Console\InstallCommand; use Vdlp\Horizon\Console\PushExampleJobsCommand; use Vdlp\Horizon\ServiceProviders\HorizonServiceProvider; @@ -49,6 +50,7 @@ public function boot(): void $this->registerConsoleCommand(PushExampleJobsCommand::class, PushExampleJobsCommand::class); } + $this->registerConsoleCommand(ClearQueuesCommand::class, ClearQueuesCommand::class); $this->registerConsoleCommand(InstallCommand::class, InstallCommand::class); } diff --git a/console/ClearQueuesCommand.php b/console/ClearQueuesCommand.php new file mode 100644 index 0000000..4aacea7 --- /dev/null +++ b/console/ClearQueuesCommand.php @@ -0,0 +1,33 @@ +name = 'vdlp:horizon:clear-queues'; + $this->description = 'Clears all the Horizon queues with one command.'; + + parent::__construct(); + } + + public function handle(Repository $config): void + { + $supervisors = $config->get('horizon.defaults'); + + foreach ($supervisors as $supervisor) { + foreach ($supervisor['queue'] as $queue) { + Artisan::call('horizon:clear', ['--queue' => $queue]); + + $this->comment(preg_replace('/\R+/', ' ', Artisan::output())); + } + } + } +}