-
Notifications
You must be signed in to change notification settings - Fork 388
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
Forever retry when job timeout #235
Comments
Workaround Set queue # .env
RABBITMQ_QUEUE_ARGUMENTS={"x-message-ttl":60000} Message is deleted from queue in specified milliseconds, so it will not be forever retried. $ while :; do php artisan queue:work --delay=1 --sleep=1 --tries=3 --timeout=3 rabbitmq; done
[2019-03-23 00:49:54][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:49:59][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:50:04][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:50:09][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:50:14][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:50:19][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:50:25][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:50:30][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:50:35][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:50:40][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:50:46][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 00:50:51][5c9582b1b9d359.01672694] Processing: App\Jobs\SampleJob
Killed However, this method can not detect job failed. |
Workaround 2 Set queue # .env
RABBITMQ_QUEUE_ARGUMENTS={"x-message-ttl":60000,"x-dead-letter-exchange":"","x-dead-letter-routing-key":"failed"} Fail jobs in # AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\MaxAttemptsExceededException;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot(QueueManager $qm)
{
$qm->before(function (JobProcessing $ev) {
if ($ev->job->getQueue() === 'failed') {
$ev->job->fail($e = new MaxAttemptsExceededException(
$ev->job->resolveName() . ' has entered dead letter.'
));
throw $e;
}
});
}
} Job sent to dead letter will be failed. $ while :; do php artisan queue:work --delay=1 --sleep=1 --tries=3 --timeout=3 --queue default,failed rabbitmq; done
[2019-03-23 02:02:18][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:02:24][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:02:29][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:02:34][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:02:39][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:02:44][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:02:50][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:02:55][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:03:00][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:03:05][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:03:11][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:03:16][5c9593a9e97648.96240097] Processing: App\Jobs\SampleJob
Killed
[2019-03-23 02:03:21][5c9593a9e97648.96240097] Failed: App\Jobs\SampleJob |
+1 - same issue here |
I will look into it. |
still an issue |
Experiencing the same issue |
I have a fix for this issue. What are the requirements to create a PR? |
@mrvtoney No formal rules for now. Just submit a PR with a short explanation and I will make a review. |
I have a solution but it requires a rework of an interaction flow with AMQP. |
v10 is released. Go and try it! |
It's still actual for me. :( |
That's correct, and by design. Normally a Job will process... its outcome will be successful or it will fail with an error in the code. When a worker timed-out, its almost impossible to know why this event occured. workers are managed and work on system signals (alarms).
To not lose the message when the worker is killed it is just rejected and requeued. In rabbitMQ this is called redelivery and a message is flagged with an boolean
If you run into a timeout issue with your workers because Jobs take too long to process:
The timeout parameter only exists for broken/dead workers, so they get removed and another process/worker may get started. Also note: when setting a timeout to low (i think below 10 sec) the workers are killed. Has something to do with the system internals. @vyuldashev What do you think? |
hi maintainer.
I have a following job class.
When job timeout, it ignores
--tries
option and retries forever.In case of redis driver, job will fails after the number of
--tries
option.The text was updated successfully, but these errors were encountered: