Doaa Magdy
Doaa Magdy

Reputation: 526

Laravel beanstalkd queue repeating jobs before retry time

I've configured a queuing on Laravel 5.4 using the "beanstalkd" queue driver ... I deployed it on CentOS 7 (cPanel) and installed Supervisor... but I've two main problems

  1. In the logs, I found this exception "local.ERROR: exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table '{dbname}.failed_jobs' doesn't exist" So Question #1 is .. Should I configure any database tables for "beanstalkd" queue driver, If so could you please state these tables structure?

  2. Also I've configured the queue:work command in the Supervisor config file as following

[program:test-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /home/****/****/artisan queue:work beanstalkd --sleep=3 --tries=3
autostart=true
autorestart=true
user=gcarpet
numprocs=8
redirect_stderr=true
stdout_logfile= /home/*****/*****/storage/logs/supervisor.log
  1. I found that the supervisor.log contained multiple calls for the job even after the first call was "Processed" .. Question #2 I dispatched the job once but the job was pushed in to the queue several times, I need a solution for this problem I don't want the same job to pushed multiple times in the queue?

    [2019-05-14 09:08:15] Processing: App\Jobs\{JobName}
    [2019-05-14 09:08:15] Processing: App\Jobs\{JobName}
    [2019-05-14 09:08:15] Failed:     App\Jobs\{JobName}
    [2019-05-14 09:08:24] Processed:  App\Jobs\{JobName}
    [2019-05-14 09:08:24] Processing: App\Jobs\{JobName}
    [2019-05-14 09:08:33] Processed:  App\Jobs\{JobName}
    [2019-05-14 09:08:33] Processing: App\Jobs\{JobName}
    [2019-05-14 09:08:41] Processed:  App\Jobs\{JobName}
    [2019-05-14 09:08:41] Processing: App\Jobs\{JobName}
    [2019-05-14 09:08:41] Failed:     App\Jobs\{JobName}
    
    1. Please note the time difference between processed and failed jobs, Also I had set the driver 'retry_after' to 900 once and to 90 another time .. And I didn't feel it made any difference.

Upvotes: 4

Views: 2457

Answers (1)

Tom
Tom

Reputation: 3351

  1. Create the table using the migration as documented.
php artisan queue:failed-table
php artisan migrate
  1. The job failed, so it is retried.

This behaviour is specified by the 'tries' option that either your queue worker receives on the command line

php artisan queue:work --tries=3

...or the tries property of the specific job.

<?php

namespace App\Jobs;

class Reader implements ShouldQueue
{
    public $tries = 5;
}

You currently are seeing that jobs retry 3 times, then fail. Check your logging output and the failed_jobs table to see what exceptions have been thrown and fix those appropriately.

A job is retried whenever the handle method throws. After a couple of retried, the job will fail and the failed() method will be invoked. Failed jobs will be stored in the failed_jobs table for later reference or manual retrying.

  1. Also note: there is a timeout and a retry after which need to be set independently.

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. If your --timeout option is longer than your retry_after configuration value, your jobs may be processed twice.

See, Job Expirations & Timeouts.

Upvotes: 2

Related Questions