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

[5.x] Implement default environment #869

Merged
merged 2 commits into from
Aug 10, 2020
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
18 changes: 10 additions & 8 deletions config/horizon.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,26 @@
|
*/

'defaults' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'simple',
'processes' => 1,
'tries' => 1,
],
],

'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'simple',
'processes' => 10,
'tries' => 1,
],
],

'local' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'simple',
'processes' => 3,
'tries' => 1,
],
],
],
Expand Down
8 changes: 5 additions & 3 deletions src/Console/TimeoutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Laravel\Horizon\Console;

use Illuminate\Console\Command;
use Laravel\Horizon\MasterSupervisor;
use Laravel\Horizon\ProvisioningPlan;

class TimeoutCommand extends Command
{
Expand Down Expand Up @@ -34,8 +36,8 @@ class TimeoutCommand extends Command
*/
public function handle()
{
$this->line(collect(
config('horizon.environments.'.$this->argument('environment'), [])
)->max('timeout') ?? 60);
$plan = ProvisioningPlan::get(MasterSupervisor::name())->plan;

$this->line(collect($plan[$this->argument('environment')] ?? [])->max('timeout') ?? 60);
}
}
21 changes: 18 additions & 3 deletions src/ProvisioningPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ class ProvisioningPlan
*
* @param string $master
* @param array $plan
* @param array $defaults
* @return void
*/
public function __construct($master, array $plan)
public function __construct($master, array $plan, array $defaults = [])
{
$this->plan = $plan;
$this->plan = $this->applyDefaultOptions($plan, $defaults);
$this->master = $master;

$this->parsed = $this->toSupervisorOptions();
Expand All @@ -54,7 +55,21 @@ public function __construct($master, array $plan)
*/
public static function get($master)
{
return new static($master, config('horizon.environments'));
return new static($master, config('horizon.environments'), config('horizon.defaults', []));
}

/**
* Apply the default supervisor options to each environment.
*
* @param array $plan
* @param array $defaults
* @return array
*/
protected function applyDefaultOptions(array $plan, array $defaults = [])
{
return collect($plan)->map(function ($plan) use ($defaults) {
return array_replace_recursive($defaults, $plan);
})->all();
}

/**
Expand Down