0
0
LaravelHow-ToBeginner · 3 min read

How to Retry Failed Job in Laravel: Simple Steps

In Laravel, you can retry a failed job using the php artisan queue:retry {id} command, where {id} is the failed job's ID. Alternatively, you can retry all failed jobs with php artisan queue:retry all to reprocess them.
📐

Syntax

Laravel provides artisan commands to retry failed jobs from the queue. You use the queue:retry command followed by the job ID or all to retry all failed jobs.

  • php artisan queue:retry {id}: Retry a specific failed job by its ID.
  • php artisan queue:retry all: Retry all failed jobs at once.
bash
php artisan queue:retry {id}
php artisan queue:retry all
💻

Example

This example shows how to retry a single failed job with ID 5 and how to retry all failed jobs using artisan commands.

bash
# Retry a single failed job with ID 5
php artisan queue:retry 5

# Retry all failed jobs
php artisan queue:retry all
Output
Retrying job ID 5... Job ID 5 has been pushed back to the queue. Retrying all failed jobs... All failed jobs have been pushed back to the queue.
⚠️

Common Pitfalls

Common mistakes when retrying failed jobs include:

  • Trying to retry a job ID that does not exist or was already deleted.
  • Not having a failed jobs table set up, so Laravel cannot track failed jobs.
  • Ignoring the root cause of failure, causing the job to fail repeatedly.
  • Not running php artisan queue:failed-table migration to create the failed jobs table.

Always check the failed jobs table and logs before retrying.

bash
/* Wrong: Retrying a non-existent job ID */
php artisan queue:retry 9999

/* Right: Check failed jobs first */
php artisan queue:failed
php artisan queue:retry 5
📊

Quick Reference

CommandDescription
php artisan queue:failedList all failed jobs
php artisan queue:retry {id}Retry a specific failed job by ID
php artisan queue:retry allRetry all failed jobs
php artisan queue:forget {id}Remove a failed job from the failed list

Key Takeaways

Use php artisan queue:retry {id} to retry a specific failed job by its ID.
Run php artisan queue:retry all to retry all failed jobs at once.
Ensure the failed jobs table exists by running php artisan queue:failed-table migration.
Check the failed jobs list with php artisan queue:failed before retrying.
Fix the underlying issue causing failure to avoid repeated job failures.