Skip to content

Commit

Permalink
ULM-403 Add clear all horizon-queues command
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark de Heij committed Sep 27, 2024
1 parent f7ab5a0 commit 912af86
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Notifications\NotificationServiceProvider;
use Laravel\Horizon\Horizon;
use System\Classes\PluginBase;
use Vdlp\Horizon\Console\ClearAllQueuesCommand;
use Vdlp\Horizon\Console\InstallCommand;
use Vdlp\Horizon\Console\PushExampleJobsCommand;
use Vdlp\Horizon\ServiceProviders\HorizonServiceProvider;
Expand Down Expand Up @@ -49,6 +50,7 @@ public function boot(): void
$this->registerConsoleCommand(PushExampleJobsCommand::class, PushExampleJobsCommand::class);
}

$this->registerConsoleCommand(ClearAllQueuesCommand::class, ClearAllQueuesCommand::class);
$this->registerConsoleCommand(InstallCommand::class, InstallCommand::class);
}

Expand Down
32 changes: 32 additions & 0 deletions console/ClearAllQueuesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Vdlp\Horizon\Console;

use Artisan;
use Illuminate\Console\Command;
use Illuminate\Contracts\Config\Repository;

final class ClearAllQueuesCommand extends Command
{
public function __construct()
{
$this->name = 'vdlp:horizon:clear-queues';
$this->description = 'Clears all the 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()));
}
}
}
}

0 comments on commit 912af86

Please sign in to comment.