7

Thank you in advance

My question is simple

For example, I have created one job which is sending an email to the user. however it is failed due to some syntax error or any other exception, so laravel will consider this job as a failed job in the failed_jobs database table, later on, let's say for an example after 2 days I found the issue in the code and I resolved it, now I want to re-run that failed job again so that my task can be complete

What is the way to do that?

Ronak Solanki
  • 341
  • 2
  • 5
  • 14

4 Answers4

10

You may view all your failed jobs using php artisan queue:failed

If you only want to retry 1 job, you can use the following (replace 5 with the ID of the job you want to retry) php artisan queue:retry 5

If you want to retry multiple jobs, you can use the following (replace the numbers with the IDs of the jobs you want to retry) php artisan queue:retry 5 6 7 8 9 10

If you want to retry a range of jobs with numeric IDs, you can use the following (replace the 5 and 10 with the range you want to retry) php artisan queue:retry --range=5-10

Finally, if you want to retry all failed jobs, you can use the following php artisan queue:retry all

These can be found here, be sure to check the docs next time:)

ITO
  • 156
  • 6
  • 1
    yes, I have read the docs but for that, we will need to run those command manually right or we can make a schedular to run that right? – Ronak Solanki Sep 18 '20 at 08:50
  • you should run it manually if it is a one time thing, (I'm assuming that it's a one time thing since you said that you found the issue and fixed it) Or do you mean retrying all failed jobs periodically or retrying them right away after failing – ITO Sep 18 '20 at 08:56
  • Thank you for `--range=5-10` - in laravel docs this is not documented/specified :) – mFlorin Apr 19 '22 at 15:10
5

It's worth noting here that jobs are serialised when pushed to the queue. Therefore if the syntax error was in the job code itself then that job will always fail.

This is because the same job payload is entered into the failed_jobs table so subsequent retries of that job will result in the same error.

omatica
  • 194
  • 2
  • 8
4

You can run a job more than 1 time

php artisan queue:work --sleep=1 --tries=5 --timeout=60

OR

You can run all failed jobs

php artisan queue:retry all

0

Just in case you need to retry failed jobs on a specific queue, you can check the answer here

Macdonald
  • 880
  • 7
  • 21