Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pbocian's avatar

Laravel Failed Jobs

Hello guys 👋

Currently Laravel Retry Command (queue:retry) fetch jobs by order id desc (->orderBy('id', 'desc')) see: DatabaseUuidFailedJobProvider::ids()

I've got two questions:

  1. What's the reason for that? From my point of view failed jobs should be put back into the jobs queue in the same order they failed. I mean the first job that failed should be first job that will be moved to the jobs queue in order to be first consumed by queue:work command
  2. How to change the implementation as the order in DatabaseUuidFailedJobProvider::ids() is hardcoded? Would it be enough to just extend DatabaseUuidFailedJobProvider and override the ids() method with different logic?

Thanks 🙏

0 likes
3 replies
Glukinho's avatar

I think you misunderstand the point of failed jobs. In Laravel, failed job is failed because something went completely and unrecoverably wrong. It means you should review logs, analyze errors maybe adjust the code and only after that, maybe, retry the job to the queue (but not necessarily!)

If you always put all your failed jobs back to the queue for retrying, I think you should adjust jobs' settings ($retries, $backoff, retryUntil(), see here: https://laravel.com/docs/12.x/queues#max-job-attempts-and-timeout) so your job can 'retry itself' several times and become failed only if there is no another way.

By default, a job fails after first thrown exception and is not retried, this behavior should be adjusted in many cases.

You currect approach considers failed_jobs table as another queue for failed jobs, which it isn't.

Snapey's avatar

I work with third party API and sometimes those API go down, resulting in a collection of failed work in the table.

I have absolutely no problem in re-queueing these in the order in which they failed (FIFO), and dont see any other strategy that makes sense.

Which is good, because that is how it works.

Glukinho's avatar

Anyway, you can retrieve failed jobs and retry them in your favorite order:

// MyCustomQueueRetryCommand

$failed_jobs = DB::table('failed_jobs')->orderBy('id', 'asc')->get();

$failed_jobs->each(function ($job) {
	Artisan::call("queue:retry {$job->uuid}");
});

Please or to participate in this conversation.