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

Reset the retryUntil value #736

Merged
merged 2 commits into from
Dec 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Jobs/RetryFailedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Horizon\Jobs;

use Cake\Chronos\Chronos;
use Illuminate\Contracts\Queue\Factory as Queue;
use Laravel\Horizon\Contracts\JobRepository;
use Laravel\Horizon\JobId;
Expand Down Expand Up @@ -55,10 +56,26 @@ public function handle(Queue $queue, JobRepository $jobs)
*/
protected function preparePayload($id, $payload)
{
return json_encode(array_merge(json_decode($payload, true), [
$payload = json_decode($payload, true);

return json_encode(array_merge($payload, [
'id' => $id,
'attempts' => 0,
'retry_of' => $this->id,
'timeoutAt' => $this->prepareNewTimeout($payload),
]));
}

/**
* Prepare the timeout.
*
* @param array $payload
* @return integer|null
*/
protected function prepareNewTimeout($payload)
{
return $payload['timeoutAt']
? Chronos::now()->addSeconds(ceil($payload['timeoutAt'] - $payload['pushedAt']))->getTimestamp()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@themsaid that is a nice solution, very good, thank you !

We had solved this internally by just overriding the RetryFailedJob class and setting timeoutAt to null, but this looks like a better approach indeed. But that's exactly why I haven't pushed a pull request; I didn't feel like I could make the best code decisions while contributing to Horizon just yet.

: null;
}
}