-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
e534b79
commit 2e0e3a2
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters