3

I know that I can retry jobs that have failed in my Laravel application by using: php artisan queue:retry 5 OR php artisan queue:retry all to push them back onto the queue.

What I would like to achieve though is to only retry failed jobs from a single queue. Such as php artisan queue:retry all --queue=emails which does not work.

I could however go through each manually by ID php artisan queue:retry 5 but this does not help if I have 1000's of records.

So in summary, my question is, how can I retry all failed jobs on specific queue?

Rob
  • 6,758
  • 4
  • 46
  • 51

2 Answers2

7

Maybe you can create another command

lets say

command : php artisan example:retry_queue emails

class RetryQueue extends Command
{
    protected $signature = 'example:retry_queue {queue_name?}';
    protected $description = 'Retry Queue';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
       // if the optional argument is set, then find all with match the queue name
       if ($this->argument('queue_name')) { 
            $queueList = FailedJobs::where('queue', $this->argument('queue_name'))->get();

            foreach($queueList as $list) {
                 Artisan::call('queue:retry '.$list->id);
            }
       } else {
            Artisan::call('queue:retry all');
       }
    }
}
ZeroOne
  • 8,996
  • 4
  • 27
  • 45
  • 1
    If it doesn't already exist in Laravel then this is a great way to achieve it. Thanks. – Rob Oct 18 '18 at 04:09
  • 2
    I was getting The command "queue:retry 6706" does not exist. I guess calling the command like Artisan::call('queue:retry', ['id' => $list->id]); will fix that. – f_i Oct 24 '19 at 12:12
  • For some reason, I could not access the FailedJobs model in Laravel 8 so I used the DB facade instead. e.g \DB::table('failed_jobs').. – Macdonald Feb 14 '22 at 10:12
0

As of Laravel 10, you can do that with a similar syntax to the one you offered. It's explained in the docs as follows:

You may also retry all of the failed jobs for a particular queue:

php artisan queue:retry --queue=name
mselmany
  • 116
  • 4