Replies: 1 comment
-
|
Short answer: No, Laravel doesn't have a built-in method for this. When you call You could: // In your job class
protected function releaseWithBackoff(): void
{
$delay = $this->getBackoffDelay();
$this->release($delay);
}
protected function getBackoffDelay(): int
{
$backoff = method_exists($this, 'backoff') ? $this->backoff() : [];
if (is_array($backoff)) {
// Use attempt - 1 since attempts() is 1-indexed
return $backoff[$this->attempts() - 1] ?? end($backoff) ?: 0;
}
return (int) $backoff;
}Or create a reusable trait: trait ReleasesWithBackoff
{
protected function releaseWithBackoff(?int $jitter = null): void
{
$delay = $this->calculateBackoffDelay();
if ($jitter) {
$delay += random_int(0, $jitter);
}
$this->release($delay);
}
protected function calculateBackoffDelay(): int
{
$backoff = method_exists($this, 'backoff') ? $this->backoff() : [];
$attempt = $this->attempts();
if (is_array($backoff)) {
return $backoff[$attempt - 1] ?? end($backoff) ?: 0;
}
return (int) $backoff;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Sometimes I don't want to throw an exception because that ends up being noise in sentry.
Is there a way to manually srelease a job back to the queue while using the backoff?
Right now I do this:
Is there a better way?
Beta Was this translation helpful? Give feedback.
All reactions