Skip to content

Commit

Permalink
apply renaming to backoff and retryUntil
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid committed May 19, 2020
1 parent cff4221 commit 6d00eb9
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
9 changes: 7 additions & 2 deletions src/Console/SupervisorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class SupervisorCommand extends Command
{name : The name of supervisor}
{connection : The name of the connection to work}
{--balance= : The balancing strategy the supervisor should apply}
{--delay=0 : Amount of time to delay failed jobs}
{--delay=0 : The number of seconds to delay failed jobs (Deprecated)}
{--backoff=0 : The number of seconds to wait before retrying a job that encountered an uncaught exception}
{--force : Force the worker to run even in maintenance mode}
{--max-processes=1 : The maximum number of total workers to start}
{--min-processes=1 : The minimum number of workers to assign per queue}
Expand Down Expand Up @@ -99,12 +100,16 @@ protected function start($supervisor)
*/
protected function supervisorOptions()
{
$backoff = $this->hasOption('backoff')
? $this->option('backoff')
: $this->option('delay');

return new SupervisorOptions(
$this->argument('name'),
$this->argument('connection'),
$this->getQueue($this->argument('connection')),
$this->option('balance'),
$this->option('delay'),
$backoff,
$this->option('max-processes'),
$this->option('min-processes'),
$this->option('memory'),
Expand Down
4 changes: 3 additions & 1 deletion src/Console/WorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class WorkCommand extends BaseWorkCommand
*/
protected $signature = 'horizon:work
{connection? : The name of the queue connection to work}
{--delay=0 : Amount of time to delay failed jobs}
{--name=default : The name of the worker}
{--delay=0 : The number of seconds to delay failed jobs (Deprecated)}
{--backoff=0 : The number of seconds to wait before retrying a job that encountered an uncaught exception}
{--daemon : Run the worker in daemon mode (Deprecated)}
{--force : Force the worker to run even in maintenance mode}
{--memory=128 : The memory limit in megabytes}
Expand Down
8 changes: 5 additions & 3 deletions src/Jobs/RetryFailedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function preparePayload($id, $payload)
'id' => $id,
'attempts' => 0,
'retry_of' => $this->id,
'timeoutAt' => $this->prepareNewTimeout($payload),
'retryUntil' => $this->prepareNewTimeout($payload),
]));
}

Expand All @@ -74,8 +74,10 @@ protected function preparePayload($id, $payload)
*/
protected function prepareNewTimeout($payload)
{
return $payload['timeoutAt']
? CarbonImmutable::now()->addSeconds(ceil($payload['timeoutAt'] - $payload['pushedAt']))->getTimestamp()
$retryUntil = $payload['retryUntil'] ?? $payload['timeoutAt'] ?? null;

return $retryUntil
? CarbonImmutable::now()->addSeconds(ceil($retryUntil - $payload['pushedAt']))->getTimestamp()
: null;
}
}
4 changes: 2 additions & 2 deletions src/QueueCommandString.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class QueueCommandString
*/
public static function toOptionsString(SupervisorOptions $options, $paused = false)
{
$string = sprintf('--delay=%s --memory=%s --queue="%s" --sleep=%s --timeout=%s --tries=%s',
$options->delay, $options->memory, $options->queue,
$string = sprintf('--backoff=%s --memory=%s --queue="%s" --sleep=%s --timeout=%s --tries=%s',
$options->backoff, $options->memory, $options->queue,
$options->sleep, $options->timeout, $options->maxTries
);

Expand Down
8 changes: 4 additions & 4 deletions src/SupervisorOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SupervisorOptions extends WorkerOptions
* @param string $connection
* @param string $queue
* @param string $balance
* @param int $delay
* @param int $backoff
* @param int $maxProcesses
* @param int $minProcesses
* @param int $memory
Expand All @@ -80,7 +80,7 @@ class SupervisorOptions extends WorkerOptions
* @param int $nice
*/
public function __construct($name, $connection, $queue = null, $balance = 'off',
$delay = 0, $maxProcesses = 1, $minProcesses = 1, $memory = 128,
$backoff = 0, $maxProcesses = 1, $minProcesses = 1, $memory = 128,
$timeout = 60, $sleep = 3, $maxTries = 0, $force = false, $nice = 0)
{
$this->name = $name;
Expand All @@ -91,7 +91,7 @@ public function __construct($name, $connection, $queue = null, $balance = 'off',
$this->minProcesses = $minProcesses;
$this->queue = $queue ?: config('queue.connections.'.$connection.'.queue');

parent::__construct($delay, $memory, $timeout, $sleep, $maxTries, $force);
parent::__construct($backoff, $memory, $timeout, $sleep, $maxTries, $force);
}

/**
Expand Down Expand Up @@ -168,7 +168,7 @@ public function toArray()
'balance' => $this->balance,
'connection' => $this->connection,
'queue' => $this->queue,
'delay' => $this->delay,
'backoff' => $this->backoff,
'force' => $this->force,
'maxProcesses' => $this->maxProcesses,
'minProcesses' => $this->minProcesses,
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->assertEquals(
'exec '.$phpBinary.' artisan horizon:supervisor my-supervisor redis --delay=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0 --balance=off --max-processes=1 --min-processes=1 --nice=0',
'exec '.$phpBinary.' artisan horizon:supervisor my-supervisor redis --backoff=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0 --balance=off --max-processes=1 --min-processes=1 --nice=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->assertEquals(
'exec '.$this->phpBinary.' worker.php redis --delay=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0 --supervisor='.$host.':name',
'exec '.$this->phpBinary.' worker.php redis --backoff=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0 --supervisor='.$host.':name',
$supervisor->processes()[0]->getCommandLine()
);
}
Expand All @@ -85,12 +85,12 @@ public function test_supervisor_starts_multiple_pools_when_balancing()
$host = MasterSupervisor::name();

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

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

0 comments on commit 6d00eb9

Please sign in to comment.