Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Refresh the retryUntil time on job retry #35780

Merged
merged 3 commits into from Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/Illuminate/Queue/Console/RetryCommand.php
Expand Up @@ -93,10 +93,25 @@ protected function getJobIdsByRanges(array $ranges)
protected function retryJob($job)
{
$this->laravel['queue']->connection($job->connection)->pushRaw(
$this->resetAttempts($job->payload), $job->queue
$this->retryRefresh($job->payload), $job->queue
);
}

/**
* Possibly refresh job attempts and retryUntil value.
*
* @param string $payload
* @return string
*/
protected function retryRefresh($payload)
{
$payload = $this->resetAttempts($payload);

$payload = $this->refreshRetryUntil($payload);

return $payload;
}

/**
* Reset the payload attempts.
*
Expand All @@ -115,4 +130,25 @@ protected function resetAttempts($payload)

return json_encode($payload);
}

/**
* Refreshes a jobs retryUntil time with it's own retryUntil method.
*
* @param string $payload
* @return string
*/
protected function refreshRetryUntil($payload)
{
$payload = json_decode($payload, true);

$jobInstance = unserialize($payload['data']['command']);

if (method_exists($jobInstance, 'retryUntil')) {
$newRetryUntil = $jobInstance->retryUntil()->timestamp;

$payload['retryUntil'] = $newRetryUntil;
}

return json_encode($payload);
}
}