Can I handle jobs timeout in Laravel?
Asked Answered
B

2

7

I'm using Laravel 5.5 and i have some jobs that are checking emails with IMAP. Sometimes that can take too long, or lets say that user mistakes port or username, it would take too long for IMAP server to respond. So I came up with idea that i can restrict my jobs to some period, but when that period expires, not only that my job isn't moved to the failed jobs, but also my worker is killed. What am I missing? Is there any other way to do this? I would like to make some changes in the DB if the job expires. Any idea? Thank you in advance

Bluefarb answered 8/2, 2018 at 15:31 Comment(0)
H
14

First, you need to manage your workers with Supervisor. If they are killed, supervisor will restart them again.
https://laravel.com/docs/5.5/queues#supervisor-configuration

After, you need to read about job expirations and timeouts in Laravel docs.
https://laravel.com/docs/5.5/queues#job-expirations-and-timeouts

To solve your problem you need to increase the --timeout of your workers. You can try with 3600 seconds. You need to increase the job expiration too (retry_after value in your queues on config/queues.php). Try with 3550 seconds. (If your --timeout option is longer than your retry_after configuration value, your jobs may be processed twice.) If you see the problem occurs again, you can increase the timeouts values.

Is very important that your code have try/catch to catch exceptions to exit if you catch an issue and don't wait 3550 seconds to release the job and the worker.

Horsefly answered 8/2, 2018 at 19:4 Comment(2)
And do you now how can I start supervisor on boot with docker ?Bluefarb
Sorry, I don't use docker.Horsefly
F
0

I always use below command for run queue (It does not have any problem):

php artisan queue:work --timeout=0 --delay=0 --memory=0 --tries=0
Fulgurating answered 7/9, 2024 at 22:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.