Skip to content

Commit 2e0e3a2

Browse files
Create status command for individual supervisors (#1467)
* Create status command for individual supervisors * formatting * Rename and register command * Update SupervisorStatusCommand.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent e534b79 commit 2e0e3a2

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Laravel\Horizon\Console;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Str;
7+
use Laravel\Horizon\Contracts\SupervisorRepository;
8+
use Laravel\Horizon\MasterSupervisor;
9+
use Symfony\Component\Console\Attribute\AsCommand;
10+
11+
#[AsCommand(name: 'horizon:supervisor-status')]
12+
class SupervisorStatusCommand extends Command
13+
{
14+
/**
15+
* The name and signature of the console command.
16+
*
17+
* @var string
18+
*/
19+
protected $signature = 'horizon:supervisor-status
20+
{name : The name of the supervisor}';
21+
22+
/**
23+
* The console command description.
24+
*
25+
* @var string
26+
*/
27+
protected $description = 'Show the status for a given supervisor';
28+
29+
/**
30+
* Execute the console command.
31+
*
32+
* @param \Laravel\Horizon\Contracts\SupervisorRepository $supervisors
33+
* @return void
34+
*/
35+
public function handle(SupervisorRepository $supervisors)
36+
{
37+
$name = $this->argument('name');
38+
39+
$supervisorStatus = optional(collect($supervisors->all())->first(function ($supervisor) use ($name) {
40+
return Str::startsWith($supervisor->name, MasterSupervisor::basename()) &&
41+
Str::endsWith($supervisor->name, $name);
42+
}))->status;
43+
44+
if (is_null($supervisorStatus)) {
45+
$this->components->error('Unable to find a supervisor with this name.');
46+
47+
return 1;
48+
}
49+
50+
$this->components->info("{$name} is {$supervisorStatus}");
51+
}
52+
}

src/HorizonServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ protected function registerCommands()
115115
Console\PurgeCommand::class,
116116
Console\StatusCommand::class,
117117
Console\SupervisorCommand::class,
118+
Console\SupervisorStatusCommand::class,
118119
Console\SupervisorsCommand::class,
119120
Console\TerminateCommand::class,
120121
Console\TimeoutCommand::class,

0 commit comments

Comments
 (0)