Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create status command for individual supervisors #1467

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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