Skip to content

Commit

Permalink
Create status command for individual supervisors (#1467)
Browse files Browse the repository at this point in the history
* Create status command for individual supervisors

* formatting

* Rename and register command

* Update SupervisorStatusCommand.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
mfrieswyk and taylorotwell authored Aug 13, 2024
1 parent e534b79 commit 2e0e3a2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Console/SupervisorStatusCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Laravel\Horizon\Console;

use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Laravel\Horizon\Contracts\SupervisorRepository;
use Laravel\Horizon\MasterSupervisor;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'horizon:supervisor-status')]
class SupervisorStatusCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'horizon:supervisor-status
{name : The name of the supervisor}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Show the status for a given supervisor';

/**
* Execute the console command.
*
* @param \Laravel\Horizon\Contracts\SupervisorRepository $supervisors
* @return void
*/
public function handle(SupervisorRepository $supervisors)
{
$name = $this->argument('name');

$supervisorStatus = optional(collect($supervisors->all())->first(function ($supervisor) use ($name) {
return Str::startsWith($supervisor->name, MasterSupervisor::basename()) &&
Str::endsWith($supervisor->name, $name);
}))->status;

if (is_null($supervisorStatus)) {
$this->components->error('Unable to find a supervisor with this name.');

return 1;
}

$this->components->info("{$name} is {$supervisorStatus}");
}
}
1 change: 1 addition & 0 deletions src/HorizonServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ protected function registerCommands()
Console\PurgeCommand::class,
Console\StatusCommand::class,
Console\SupervisorCommand::class,
Console\SupervisorStatusCommand::class,
Console\SupervisorsCommand::class,
Console\TerminateCommand::class,
Console\TimeoutCommand::class,
Expand Down

0 comments on commit 2e0e3a2

Please sign in to comment.