4

I have a Laravel with some Jobs that are usually very quick to run. Hence I have configured my default retry_after in config/queue.php to 20 seconds

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

I do however have one type of Jobs that can take much longer, up to a few minutes, so I have upgraded to Laravel 5.8 to be able to specify a retry-after parameter specific to this class:

class LongJob implements ShouldQueue {
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $timeout = 600;
    public $tries = 3;
    public $retryAfter = 610;

However, when I dispatch a LongJob to the queue, I find in my logs that the job is called twice, i.e., at dispatch, and then 20 seconds after.

Can you think of any reason why Laravel would not "see" my $retryAfter option - which from what I understand is supposed to override the global setting?

EDIT: after further testing, it seems that $retryAfter and retry_after do not work exactly the same... From what I've tried:

  • a job will be attempted again after retry_after seconds, regardless of whether it's still running from a previous attempt
  • when a job fails and is released back into the queue, it will attempted again after $retryAfter seconds

Hence in my case, correct values would be:

retry_after = 610; //As long as the longest timeout is + small buffer
$retryAfter = 5; //I'd like my job to be re-attempted quickly after it fails

Not sure if a bug or a feature...

Buno
  • 597
  • 1
  • 9
  • 20
  • Did you restart your queue after you added `$retryAfter` to your job? – Rwd Jul 08 '19 at 06:28
  • Yes :( nice to point it out though, I've made that mistake in the past.. – Buno Jul 08 '19 at 07:17
  • Which queue worker are you using? – Rwd Jul 08 '19 at 07:42
  • The "default" queue worker with supervisor keeping it running – Buno Jul 08 '19 at 09:59
  • Sorry, I meant what connection are you using i.e. redis, db, beanstalkd, sqs etc.? – Rwd Jul 08 '19 at 13:14
  • Oh, using the db driver. I've edited my original post with additional info, it seems maybe the "retry after" option does not work as expected (or at least as I expected it to work) – Buno Jul 09 '19 at 02:20
  • Can you let me know exactly what version of 5.8 you have installed? – Rwd Jul 09 '19 at 07:49
  • Laravel Framework 5.8.27 sir! – Buno Jul 09 '19 at 12:32
  • Have you solved this? – Ivan Carosati Feb 22 '20 at 21:43
  • Not really no. The "workaround" I ended up adopting was to set retry_after in the queue driver to a long value (longer than the timeout value of my longest job), and set a $retryAfter parameter individually in each job – Buno Feb 23 '20 at 22:24
  • any solution ?? i also have same question https://stackoverflow.com/questions/63816367/getting-illuminate-queue-maxattemptsexceededexception-in-laravel-jobs @Buno – Jigar Sep 10 '20 at 16:49

0 Answers0