diff --git a/src/Console/SupervisorCommand.php b/src/Console/SupervisorCommand.php index c50ef401..b59157a5 100644 --- a/src/Console/SupervisorCommand.php +++ b/src/Console/SupervisorCommand.php @@ -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} @@ -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'), diff --git a/src/Console/WorkCommand.php b/src/Console/WorkCommand.php index 3a1e2ba6..a477eb5e 100644 --- a/src/Console/WorkCommand.php +++ b/src/Console/WorkCommand.php @@ -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} diff --git a/src/Jobs/RetryFailedJob.php b/src/Jobs/RetryFailedJob.php index 46d718f5..b5a5b68e 100644 --- a/src/Jobs/RetryFailedJob.php +++ b/src/Jobs/RetryFailedJob.php @@ -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), ])); } @@ -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; } } diff --git a/src/QueueCommandString.php b/src/QueueCommandString.php index 35c9c739..cf46b2e3 100644 --- a/src/QueueCommandString.php +++ b/src/QueueCommandString.php @@ -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 ); diff --git a/src/SupervisorOptions.php b/src/SupervisorOptions.php index 579f2234..a64d2d93 100644 --- a/src/SupervisorOptions.php +++ b/src/SupervisorOptions.php @@ -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 @@ -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; @@ -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); } /** @@ -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, diff --git a/tests/Feature/AddSupervisorTest.php b/tests/Feature/AddSupervisorTest.php index d3c6ad02..f4a878fe 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->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() ); } diff --git a/tests/Feature/SupervisorTest.php b/tests/Feature/SupervisorTest.php index db7e4ac3..a8912c5e 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->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() ); } @@ -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() ); }