-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Queue worker ignores job's maxTries setting if using retryUntil() #35199
Comments
IMO |
That's how I thought it worked originally and I think that makes more sense. That is, I thought
And when an exception is thrown, it will check the framework/src/Illuminate/Queue/Worker.php Lines 504 to 506 in 72ea7ba
|
Either way, it seems like these two methods shouldn't contain different logic: framework/src/Illuminate/Queue/Worker.php Lines 468 to 485 in e9483c4
framework/src/Illuminate/Queue/Worker.php Lines 496 to 507 in e9483c4
|
We need to decide which logic we want to keep and change the other one. Should |
I think what you did in the PR is the best approach: |
I have the same issue. I think maybe you can affect tries to queue run. |
I found this issue during a search, thinking something was broken. The quoted logic makes sense but it should be more explicitly explained in the documentation that |
Description:
There is a discrepancy between how the worker treats
$job->retryUntil()
and$job->maxTries()
depending on whether an exception is thrown. This only affects jobs whereretryUntil()
is used.Essentially, if a job throws an exception, if either
$job->retryUntil()
is exceeded or$job->maxTries()
is exceeded, the job fails. This seems to be the expected behavior.However, if the job doesn't throw an exception, but is just released (such as when using a rate limit middleware), then only
$job->retryUntil()
is considered and$job->maxTries()
doesn't matter.Steps To Reproduce:
Job that throws an exception:
$tries=5
andretryUntil() { return now()->addHour(); }
.Job that is just released:
$tries=5
andretryUntil() { return now()->addHour(); }
.Note that in either case (whether throwing an exception or releasing the job), the number of attempts is incremented.
Details:
When picking up a job, the worker first checks the number of attempts:
framework/src/Illuminate/Queue/Worker.php
Lines 395 to 397 in 72ea7ba
This method prioritizes
retryUntil()
. That is, if you use$job->retryUntil()
, it doesn't matter what the$tries
property is on the job or the--tries
parameter is on the worker. The$job->retryUntil()
method essentially overrides them:framework/src/Illuminate/Queue/Worker.php
Lines 474 to 480 in 72ea7ba
If the job throws an exception, the worker again checks the number of attempts:
framework/src/Illuminate/Queue/Worker.php
Lines 432 to 434 in 72ea7ba
But this time,
retryUntil()
is not prioritized. Meaning, if either the time set inretryUntil()
is passed or the max attempts (as specified on the job or worker) is exceeded, the job will be marked as failed:framework/src/Illuminate/Queue/Worker.php
Lines 500 to 506 in 72ea7ba
The text was updated successfully, but these errors were encountered: