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

[3.0] Adding horizon:status command #545

Merged
merged 2 commits into from
Mar 8, 2019
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
51 changes: 51 additions & 0 deletions src/Console/StatusCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Laravel\Horizon\Console;

use Illuminate\Console\Command;
use Laravel\Horizon\Contracts\MasterSupervisorRepository;

class StatusCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'horizon:status';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Get the current status of Horizon.';

/**
* Execute the console command.
*
* @param \Laravel\Horizon\Contracts\MasterSupervisorRepository $masterSupervisorRepository
* @return void
*/
public function handle(MasterSupervisorRepository $masterSupervisorRepository)
{
$this->line($this->currentStatus($masterSupervisorRepository));
}

/**
* Get the current status of Horizon.
*
* @param \Laravel\Horizon\Contracts\MasterSupervisorRepository $masterSupervisorRepository
* @return string
*/
protected function currentStatus(MasterSupervisorRepository $masterSupervisorRepository)
{
if (! $masters = $masterSupervisorRepository->all()) {
return 'inactive';
}

return collect($masters)->contains(function ($master) {
return $master->status === 'paused';
}) ? 'paused' : 'running';
}
}
1 change: 1 addition & 0 deletions src/HorizonServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ protected function registerCommands()
Console\TerminateCommand::class,
Console\TimeoutCommand::class,
Console\WorkCommand::class,
Console\StatusCommand::class,
]);
}

Expand Down