Skip to content

Commit b2ef789

Browse files
authored
Merge pull request #151 from xav-developer/fix/stuck-tasks
Tasks were stuck in case of an error, the "release" method did not return them to the queue.
2 parents 8893e21 + 2f3f5be commit b2ef789

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog][keepachangelog] and this project adher
66

77
### Fixed
88

9+
- Tasks were stuck in case of an error, the "release" method did not return them to the queue.
10+
- The "calculateBackoff" method incorrectly took the index "$job->attempts()"
911
- The "withHeader" method of the "\Spiral\RoadRunner\Jobs\Task\WritableHeadersInterface" interface expects the type "string|iterable", "int" is passed
1012

1113
## v5.12.0

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)