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] Add Supervisor Rest Option #992

Merged
merged 2 commits into from
Mar 30, 2021
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
6 changes: 4 additions & 2 deletions src/Console/SupervisorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class SupervisorCommand extends Command
{--balance-cooldown=3 : The number of seconds to wait in between auto-scaling attempts}
{--balance-max-shift=1 : The maximum number of processes to increase or decrease per one scaling}
{--workers-name=default : The name that should be assigned to the workers}
{--parent-id=0 : The parent process ID}';
{--parent-id=0 : The parent process ID}
{--rest=0 : Number of seconds to rest between jobs}';

/**
* The console command description.
Expand Down Expand Up @@ -129,7 +130,8 @@ protected function supervisorOptions()
$this->option('nice'),
$this->option('balance-cooldown'),
$this->option('balance-max-shift'),
$this->option('parent-id')
$this->option('parent-id'),
$this->option('rest')
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/QueueCommandString.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public static function toSupervisorOptionsString(SupervisorOptions $options)
*/
public static function toOptionsString(SupervisorOptions $options, $paused = false)
{
$string = sprintf('--backoff=%s --max-time=%s --max-jobs=%s --memory=%s --queue="%s" --sleep=%s --timeout=%s --tries=%s',
$string = sprintf('--backoff=%s --max-time=%s --max-jobs=%s --memory=%s --queue="%s" --sleep=%s --timeout=%s --tries=%s --rest=%s',
$options->backoff, $options->maxTime, $options->maxJobs, $options->memory,
$options->queue, $options->sleep, $options->timeout, $options->maxTries
$options->queue, $options->sleep, $options->timeout, $options->maxTries, $options->rest
);

if ($options->force) {
Expand Down
13 changes: 12 additions & 1 deletion src/SupervisorOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ class SupervisorOptions
*/
public $force;

/**
* The number of seconds to rest between jobs.
*
* @var int
*/
public $rest;

/**
* Create a new worker options instance.
*
Expand All @@ -166,6 +173,7 @@ class SupervisorOptions
* @param int $balanceCooldown
* @param int $balanceMaxShift
* @param int $parentId
* @param int $rest
*/
public function __construct($name,
$connection,
Expand All @@ -185,7 +193,8 @@ public function __construct($name,
$nice = 0,
$balanceCooldown = 3,
$balanceMaxShift = 1,
$parentId = 0)
$parentId = 0,
$rest = 0)
{
$this->name = $name;
$this->connection = $connection;
Expand All @@ -206,6 +215,7 @@ public function __construct($name,
$this->balanceCooldown = $balanceCooldown;
$this->balanceMaxShift = $balanceMaxShift;
$this->parentId = $parentId;
$this->rest = $rest;
}

/**
Expand Down Expand Up @@ -298,6 +308,7 @@ public function toArray()
'balanceCooldown' => $this->balanceCooldown,
'balanceMaxShift' => $this->balanceMaxShift,
'parentId' => $this->parentId,
'rest' => $this->rest,
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/AddSupervisorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function test_add_supervisor_command_creates_new_supervisor_on_master_pro
$this->assertCount(1, $master->supervisors);

$this->assertSame(
'exec '.$phpBinary.' artisan horizon:supervisor my-supervisor redis --workers-name=default --balance=off --max-processes=1 --min-processes=1 --nice=0 --balance-cooldown=3 --balance-max-shift=1 --parent-id=0 --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0',
'exec '.$phpBinary.' artisan horizon:supervisor my-supervisor redis --workers-name=default --balance=off --max-processes=1 --min-processes=1 --nice=0 --balance-cooldown=3 --balance-max-shift=1 --parent-id=0 --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0 --rest=0',
$master->supervisors->first()->process->getCommandLine()
);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/SupervisorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function test_supervisor_can_start_worker_process_with_given_options()

$host = MasterSupervisor::name();
$this->assertSame(
'exec '.$this->phpBinary.' worker.php redis --name=default --supervisor='.$host.':name --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0',
'exec '.$this->phpBinary.' worker.php redis --name=default --supervisor='.$host.':name --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0 --rest=0',
$supervisor->processes()[0]->getCommandLine()
);
}
Expand All @@ -85,12 +85,12 @@ public function test_supervisor_starts_multiple_pools_when_balancing()
$host = MasterSupervisor::name();

$this->assertSame(
'exec '.$this->phpBinary.' worker.php redis --name=default --supervisor='.$host.':name --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue="first" --sleep=3 --timeout=60 --tries=0',
'exec '.$this->phpBinary.' worker.php redis --name=default --supervisor='.$host.':name --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue="first" --sleep=3 --timeout=60 --tries=0 --rest=0',
$supervisor->processes()[0]->getCommandLine()
);

$this->assertSame(
'exec '.$this->phpBinary.' worker.php redis --name=default --supervisor='.$host.':name --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue="second" --sleep=3 --timeout=60 --tries=0',
'exec '.$this->phpBinary.' worker.php redis --name=default --supervisor='.$host.':name --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue="second" --sleep=3 --timeout=60 --tries=0 --rest=0',
$supervisor->processes()[1]->getCommandLine()
);
}
Expand Down