From 3d42f9a6bfb89dc726525f6e0bdc24b8e20605a2 Mon Sep 17 00:00:00 2001 From: Craig Anderson Date: Tue, 30 Mar 2021 15:17:02 -0400 Subject: [PATCH] [5.x] Add Supervisor Rest Option (#992) * Add Supervisor Rest Option * Change argument order to prevent breaking change --- src/Console/SupervisorCommand.php | 6 ++++-- src/QueueCommandString.php | 4 ++-- src/SupervisorOptions.php | 13 ++++++++++++- tests/Feature/AddSupervisorTest.php | 2 +- tests/Feature/SupervisorTest.php | 6 +++--- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Console/SupervisorCommand.php b/src/Console/SupervisorCommand.php index ead85e10..f35c9b6c 100644 --- a/src/Console/SupervisorCommand.php +++ b/src/Console/SupervisorCommand.php @@ -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. @@ -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') ); } diff --git a/src/QueueCommandString.php b/src/QueueCommandString.php index be03d3ec..0277b581 100644 --- a/src/QueueCommandString.php +++ b/src/QueueCommandString.php @@ -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) { diff --git a/src/SupervisorOptions.php b/src/SupervisorOptions.php index fc276d03..95721094 100644 --- a/src/SupervisorOptions.php +++ b/src/SupervisorOptions.php @@ -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. * @@ -166,6 +173,7 @@ class SupervisorOptions * @param int $balanceCooldown * @param int $balanceMaxShift * @param int $parentId + * @param int $rest */ public function __construct($name, $connection, @@ -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; @@ -206,6 +215,7 @@ public function __construct($name, $this->balanceCooldown = $balanceCooldown; $this->balanceMaxShift = $balanceMaxShift; $this->parentId = $parentId; + $this->rest = $rest; } /** @@ -298,6 +308,7 @@ public function toArray() 'balanceCooldown' => $this->balanceCooldown, 'balanceMaxShift' => $this->balanceMaxShift, 'parentId' => $this->parentId, + 'rest' => $this->rest, ]; } diff --git a/tests/Feature/AddSupervisorTest.php b/tests/Feature/AddSupervisorTest.php index 9f1431e6..f2af33d3 100644 --- a/tests/Feature/AddSupervisorTest.php +++ b/tests/Feature/AddSupervisorTest.php @@ -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() ); } diff --git a/tests/Feature/SupervisorTest.php b/tests/Feature/SupervisorTest.php index 61cbde92..28d8c146 100644 --- a/tests/Feature/SupervisorTest.php +++ b/tests/Feature/SupervisorTest.php @@ -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() ); } @@ -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() ); }