Skip to content

Fix: Make sure that missing supervisors are correctly displayed when using multiple environments #1294

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

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
8 changes: 4 additions & 4 deletions src/Console/HorizonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public function handle(MasterSupervisorRepository $masters)
return $this->comment('A master supervisor is already running on this machine.');
}

$master = (new MasterSupervisor)->handleOutputUsing(function ($type, $line) {
$environment = $this->option('environment') ?? config('horizon.env') ?? config('app.env');

$master = (new MasterSupervisor($environment))->handleOutputUsing(function ($type, $line) {
$this->output->write($line);
});

ProvisioningPlan::get(MasterSupervisor::name())->deploy(
$this->option('environment') ?? config('horizon.env') ?? config('app.env')
);
ProvisioningPlan::get(MasterSupervisor::name())->deploy($environment);

$this->info('Horizon started successfully.');

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/MasterSupervisorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function index(MasterSupervisorRepository $masters,
return $masters->each(function ($master, $name) use ($supervisors) {
$master->supervisors = ($supervisors->get($name) ?? collect())
->merge(
collect(ProvisioningPlan::get($name)->plan[config('horizon.env') ?? config('app.env')] ?? [])
collect(ProvisioningPlan::get($name)->plan[$master->environment ?? config('horizon.env') ?? config('app.env')] ?? [])
->map(function ($value, $key) use ($name) {
return (object) [
'name' => $name.':'.$key,
Expand Down
12 changes: 11 additions & 1 deletion src/MasterSupervisor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class MasterSupervisor implements Pausable, Restartable, Terminable
{
use ListensForSignals;

/**
* The environment that was used to provision this master supervisor.
*
* @var string|null
*/
public $environment;

/**
* The name of the master supervisor.
*
Expand Down Expand Up @@ -59,10 +66,13 @@ class MasterSupervisor implements Pausable, Restartable, Terminable
/**
* Create a new master supervisor instance.
*
* @param string $environment
* @return void
*/
public function __construct()
public function __construct(string $environment = null)
{
$this->environment = $environment;

$this->name = static::name();
$this->supervisors = collect();

Expand Down
10 changes: 6 additions & 4 deletions src/Repositories/RedisMasterSupervisorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function get(array $names)
{
$records = $this->connection()->pipeline(function ($pipe) use ($names) {
foreach ($names as $name) {
$pipe->hmget('master:'.$name, ['name', 'pid', 'status', 'supervisors']);
$pipe->hmget('master:'.$name, ['name', 'environment', 'pid', 'status', 'supervisors']);
}
});

Expand All @@ -81,9 +81,10 @@ public function get(array $names)

return ! $record[0] ? null : (object) [
'name' => $record[0],
'pid' => $record[1],
'status' => $record[2],
'supervisors' => json_decode($record[3], true),
'environment' => $record[1],
'pid' => $record[2],
'status' => $record[3],
'supervisors' => json_decode($record[4], true),
];
})->filter()->all();
}
Expand All @@ -102,6 +103,7 @@ public function update(MasterSupervisor $master)
$pipe->hmset(
'master:'.$master->name, [
'name' => $master->name,
'environment' => $master->environment,
'pid' => $master->pid(),
'status' => $master->working ? 'running' : 'paused',
'supervisors' => json_encode($supervisors),
Expand Down