Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon can I retry failed jobs in batches using Laravel


can I retry failed jobs in batches using Laravel


Yes, you can retry failed jobs in batches using Laravel. Here are the steps to do so:

Installation

You can install the `kirschbaum-development/laravel-queue-batch-retry` package via Composer:

bash
composer require kirschbaum-development/laravel-queue-batch-retry

Usage

The package provides two commands:

1. `queue:failed:batch-retry`: This command allows you to retry failed jobs in batches. You can use various filters and options to specify which jobs to retry.

Example:

bash
php artisan queue:failed:batch-retry --failed-after="2 days ago" --queue="default" --limit=10 --filter="CrawlWebsiteJob" --filter-by-exception="ModelNotFoundException"

2. `queue:failed:batch-delete`: This command allows you to delete failed jobs in batches. You can use the same filters and options as the `queue:failed:batch-retry` command.

Filters and Options

The `queue:failed:batch-retry` command supports several filters and options:

- `--filter`: Searches for jobs by their payload.
- `--exclude-filter`: Excludes jobs by their payload.
- `--filter-by-exception`: Searches for jobs by their exception.
- `--failed-after`: Filters jobs by their failure time.
- `--failed-before`: Filters jobs by their failure time.
- `--limit`: Limits the number of jobs to retry.
- `--dry-run`: Runs a dry run to see what jobs would be retried.

Example

Here is an example of how to retry all failed jobs in batches:

bash
php artisan queue:failed:batch-retry --queue="default"

Conclusion

Laravel provides robust mechanisms for handling job retries and failures. By using the `kirschbaum-development/laravel-queue-batch-retry` package, you can retry failed jobs in batches, ensuring efficient and reliable processing of your background tasks.

Citations:
[1] https://github.com/kirschbaum-development/laravel-queue-batch-retry
[2] https://github.com/laravel/framework/issues/34899
[3] https://stackoverflow.com/questions/30778924/laravel-4-retry-all-failed-jobs
[4] https://laravel.com/docs/11.x/queues
[5] https://stackoverflow.com/questions/63951783/laravel-queue-and-jobs-how-to-re-run-failed-job-later-on