Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon how does the --failed-after option work for retrying jobs
    Laravel queue:failed:batch-retry --failed-after filter failed jobs Laravel retry options job failure time Laravel command options


how does the --failed-after option work for retrying jobs


The `--failed-after` option in the `queue:failed:batch-retry` command in Laravel allows you to filter the failed jobs based on the time they failed.

Here's how it works:

1. Filtering by Failed Time: The `--failed-after` option allows you to specify a date/time after which the failed jobs were created. This helps you target only the jobs that failed after a certain point in time.

2. Supported Formats: The `--failed-after` option accepts various date/time formats, such as:
- `"2 days ago"`: Selects jobs that failed in the last 2 days
- `"yesterday"`: Selects jobs that failed yesterday
- `"2023-04-01"`: Selects jobs that failed on April 1, 2023
- `"2023-04-01 12:00:00"`: Selects jobs that failed on April 1, 2023 at 12:00:00

3. Combination with Other Filters: You can combine the `--failed-after` option with other filters, such as `--filter`, `--filter-by-exception`, and `--limit`, to further refine the set of jobs you want to retry.

For example, the following command would retry all failed jobs that occurred in the last 2 days, and were caused by a `ModelNotFoundException`:


php artisan queue:failed:batch-retry --failed-after="2 days ago" --filter-by-exception="ModelNotFoundException"

This allows you to selectively retry only the failed jobs that are relevant to your current issue, without having to manually sift through the entire `failed_jobs` table.

The `--failed-before` option works in a similar way, but it allows you to filter jobs that failed before a certain date/time instead of after.

By using the `--failed-after` (and optionally `--failed-before`) options, you can effectively target and retry the specific set of failed jobs that you need to address, making the process more efficient and manageable.

Citations:
[1] https://github.com/kirschbaum-development/laravel-queue-batch-retry
[2] https://stackoverflow.com/questions/30778924/laravel-4-retry-all-failed-jobs
[3] https://stackoverflow.com/questions/63951783/laravel-queue-and-jobs-how-to-re-run-failed-job-later-on
[4] https://www.honeybadger.io/blog/laravel-queues-deep-dive/
[5] https://ahmedshamim.com/posts/retry-mechanisms-in-laravel