Skip to content

Commit edb9cce

Browse files
committed
Tasks were stuck in case of an error, the "release" method did not return them to the queue.
The "calculateBackoff" method incorrectly took the index "$job->attempts()"
1 parent 8893e21 commit edb9cce

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Queue/QueueWorker.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ protected function failJob(RoadRunnerJob $job, \Throwable $e): void
187187
protected function maxAttemptsExceededException(RoadRunnerJob $job): MaxAttemptsExceededException
188188
{
189189
return new MaxAttemptsExceededException(
190-
$job->resolveName(
191-
) . ' has been attempted too many times or run too long. The job may have previously timed out.',
190+
$job->resolveName() . ' has been attempted too many times or run too long. The job may have previously timed out.',
192191
);
193192
}
194193

@@ -267,9 +266,9 @@ protected function calculateBackoff(RoadRunnerJob $job, WorkerOptions $options):
267266
',',
268267
\method_exists($job, 'backoff') && !\is_null($job->backoff())
269268
? $job->backoff()
270-
: $options->backoff,
269+
: (string) $options->backoff,
271270
);
272271

273-
return (int) ($backoff[$job->attempts() - 1] ?? last($backoff));
272+
return (int) ($backoff[$job->attempts()] ?? last($backoff));
274273
}
275274
}

src/Queue/RoadRunnerJob.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ public function fire(): void
4848
$this->task->complete();
4949
}
5050

51+
public function release($delay = 0): void
52+
{
53+
$attempts = $this->attempts();
54+
55+
$this->task
56+
->withDelay($delay)
57+
->withHeader('attempts', (string) ++$attempts)
58+
->requeue('release');
59+
60+
parent::release($delay);
61+
}
62+
5163
protected function failed($e): void
5264
{
5365
$attempts = $this->attempts();

0 commit comments

Comments
 (0)