jeudi 2 septembre 2021

Laravel Queues - why is Queue job retrying every 3 seconds, if I specify timeout=5 and expire=>7?

I am trying to set up my queue worker in Laravel 5.3 and am trying to ensure that I fully understand nuances of the interrelated parameters expire, --tries, --timeout, because the results I am seeing suggest I am not understanding something.

Note: In the Laravel 5.3 documentation (https://laravel.com/docs/5.3/queues#introduction), it refers to retry_after as being a parameter for the database queue connection type, but in my installation of Laravel 5.3, that parameter seems to be expire.

In any case, I have a job, let's call it SendReminder. I purposefully added a line of code that causes an error, so I can test the functioning of the queue tries/retries and eventual labeling of the job as failed in the failed_jobs table.

Here is my database queue config in queue.php:

        'database' => [
            'driver' => 'database',
            'table'  => 'jobs',
            'queue'  => 'default',
            'retry_after' => 7,
            'expire' => 7,
        ],

For testing, I want to let it try 3 times before being sent to failed_jobs table.

I expect the job to take not more than 5 seconds, and so setting --timeout=5, and expire to 7 (or retry_after to 7), would seem to be in line with the Queue documentation, which says "The --timeout value should always be at least several seconds shorter than your retry_after configuration value. This will ensure that a worker processing a given job is always killed before the job is retried."

Based on above, I expect the job to be considered failed after 21 seconds.

After running php artisan queue:work --daemon --queue=email,default --timeout=5 --tries=3 and then dispatching the job via php artisan schedule:run >> /dev/null 2>&1

I count with my stopwatch 9 seconds until the queue worker displays

[2021-09-02 14:22:14] Failed: App\Jobs\PrepareSendReminderJob

and in my Laravel log I see

[2021-09-02 14:22:08] local.ERROR: ErrorException:
[2021-09-02 14:22:11] local.ERROR: ErrorException:
[2021-09-02 14:22:14] local.ERROR: ErrorException:

This doesn't seem to make sense. I would expect, based on my expire being set to 7, that the failure message would only come 21 seconds after the job is dispatched and immediately picked up by the queue. And I get same result every time - 3 seconds between each error message in the log.

Can someone explain why I am seeing this result?

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire