Skip to content

Commit 6d00eb9

Browse files
committed
apply renaming to backoff and retryUntil
1 parent cff4221 commit 6d00eb9

7 files changed

+25
-16
lines changed

src/Console/SupervisorCommand.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class SupervisorCommand extends Command
1818
{name : The name of supervisor}
1919
{connection : The name of the connection to work}
2020
{--balance= : The balancing strategy the supervisor should apply}
21-
{--delay=0 : Amount of time to delay failed jobs}
21+
{--delay=0 : The number of seconds to delay failed jobs (Deprecated)}
22+
{--backoff=0 : The number of seconds to wait before retrying a job that encountered an uncaught exception}
2223
{--force : Force the worker to run even in maintenance mode}
2324
{--max-processes=1 : The maximum number of total workers to start}
2425
{--min-processes=1 : The minimum number of workers to assign per queue}
@@ -99,12 +100,16 @@ protected function start($supervisor)
99100
*/
100101
protected function supervisorOptions()
101102
{
103+
$backoff = $this->hasOption('backoff')
104+
? $this->option('backoff')
105+
: $this->option('delay');
106+
102107
return new SupervisorOptions(
103108
$this->argument('name'),
104109
$this->argument('connection'),
105110
$this->getQueue($this->argument('connection')),
106111
$this->option('balance'),
107-
$this->option('delay'),
112+
$backoff,
108113
$this->option('max-processes'),
109114
$this->option('min-processes'),
110115
$this->option('memory'),

src/Console/WorkCommand.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class WorkCommand extends BaseWorkCommand
1313
*/
1414
protected $signature = 'horizon:work
1515
{connection? : The name of the queue connection to work}
16-
{--delay=0 : Amount of time to delay failed jobs}
16+
{--name=default : The name of the worker}
17+
{--delay=0 : The number of seconds to delay failed jobs (Deprecated)}
18+
{--backoff=0 : The number of seconds to wait before retrying a job that encountered an uncaught exception}
1719
{--daemon : Run the worker in daemon mode (Deprecated)}
1820
{--force : Force the worker to run even in maintenance mode}
1921
{--memory=128 : The memory limit in megabytes}

src/Jobs/RetryFailedJob.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function preparePayload($id, $payload)
6262
'id' => $id,
6363
'attempts' => 0,
6464
'retry_of' => $this->id,
65-
'timeoutAt' => $this->prepareNewTimeout($payload),
65+
'retryUntil' => $this->prepareNewTimeout($payload),
6666
]));
6767
}
6868

@@ -74,8 +74,10 @@ protected function preparePayload($id, $payload)
7474
*/
7575
protected function prepareNewTimeout($payload)
7676
{
77-
return $payload['timeoutAt']
78-
? CarbonImmutable::now()->addSeconds(ceil($payload['timeoutAt'] - $payload['pushedAt']))->getTimestamp()
77+
$retryUntil = $payload['retryUntil'] ?? $payload['timeoutAt'] ?? null;
78+
79+
return $retryUntil
80+
? CarbonImmutable::now()->addSeconds(ceil($retryUntil - $payload['pushedAt']))->getTimestamp()
7981
: null;
8082
}
8183
}

src/QueueCommandString.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class QueueCommandString
1313
*/
1414
public static function toOptionsString(SupervisorOptions $options, $paused = false)
1515
{
16-
$string = sprintf('--delay=%s --memory=%s --queue="%s" --sleep=%s --timeout=%s --tries=%s',
17-
$options->delay, $options->memory, $options->queue,
16+
$string = sprintf('--backoff=%s --memory=%s --queue="%s" --sleep=%s --timeout=%s --tries=%s',
17+
$options->backoff, $options->memory, $options->queue,
1818
$options->sleep, $options->timeout, $options->maxTries
1919
);
2020

src/SupervisorOptions.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SupervisorOptions extends WorkerOptions
6969
* @param string $connection
7070
* @param string $queue
7171
* @param string $balance
72-
* @param int $delay
72+
* @param int $backoff
7373
* @param int $maxProcesses
7474
* @param int $minProcesses
7575
* @param int $memory
@@ -80,7 +80,7 @@ class SupervisorOptions extends WorkerOptions
8080
* @param int $nice
8181
*/
8282
public function __construct($name, $connection, $queue = null, $balance = 'off',
83-
$delay = 0, $maxProcesses = 1, $minProcesses = 1, $memory = 128,
83+
$backoff = 0, $maxProcesses = 1, $minProcesses = 1, $memory = 128,
8484
$timeout = 60, $sleep = 3, $maxTries = 0, $force = false, $nice = 0)
8585
{
8686
$this->name = $name;
@@ -91,7 +91,7 @@ public function __construct($name, $connection, $queue = null, $balance = 'off',
9191
$this->minProcesses = $minProcesses;
9292
$this->queue = $queue ?: config('queue.connections.'.$connection.'.queue');
9393

94-
parent::__construct($delay, $memory, $timeout, $sleep, $maxTries, $force);
94+
parent::__construct($backoff, $memory, $timeout, $sleep, $maxTries, $force);
9595
}
9696

9797
/**
@@ -168,7 +168,7 @@ public function toArray()
168168
'balance' => $this->balance,
169169
'connection' => $this->connection,
170170
'queue' => $this->queue,
171-
'delay' => $this->delay,
171+
'backoff' => $this->backoff,
172172
'force' => $this->force,
173173
'maxProcesses' => $this->maxProcesses,
174174
'minProcesses' => $this->minProcesses,

tests/Feature/AddSupervisorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function test_add_supervisor_command_creates_new_supervisor_on_master_pro
2828
$this->assertCount(1, $master->supervisors);
2929

3030
$this->assertEquals(
31-
'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',
31+
'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',
3232
$master->supervisors->first()->process->getCommandLine()
3333
);
3434
}

tests/Feature/SupervisorTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function test_supervisor_can_start_worker_process_with_given_options()
6767

6868
$host = MasterSupervisor::name();
6969
$this->assertEquals(
70-
'exec '.$this->phpBinary.' worker.php redis --delay=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0 --supervisor='.$host.':name',
70+
'exec '.$this->phpBinary.' worker.php redis --backoff=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0 --supervisor='.$host.':name',
7171
$supervisor->processes()[0]->getCommandLine()
7272
);
7373
}
@@ -85,12 +85,12 @@ public function test_supervisor_starts_multiple_pools_when_balancing()
8585
$host = MasterSupervisor::name();
8686

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

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

0 commit comments

Comments
 (0)