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())); + } + } + } +}