Skip to content

Commit

Permalink
Add Clear Queues Command (#5)
Browse files Browse the repository at this point in the history
Add clear-queues console command

---------

Co-authored-by: Mark de Heij <m.deheij@vdlp.nl>
Co-authored-by: Sander Beenen <sander@sbeenen.nl>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent f7ab5a0 commit 55e4182
Show file tree
Hide file tree
Showing 2 changed files with 35 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\ClearQueuesCommand;
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(ClearQueuesCommand::class, ClearQueuesCommand::class);
$this->registerConsoleCommand(InstallCommand::class, InstallCommand::class);
}

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

declare(strict_types=1);

namespace Vdlp\Horizon\Console;

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

final class ClearQueuesCommand extends Command
{
public function __construct()
{
$this->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()));
}
}
}
}

0 comments on commit 55e4182

Please sign in to comment.