Ever ran into an issue where Laravel Horizon doesn't clear failed jobs even after you run
php artisan queue:flush? Right now it clears automatically in 7 days, but sometimes during development you need to clear it right away so you can test new changes.
Currently there's no support built inside Laravel to do that and there's no button in Horizon's UI to clear this either. So this issue is kind of frustrating.
Here's what I've done to flush failed Redis jobs with a simple command:
Create a new command:
php artisan make:command FlushRedis --command=flush:redis
use statement to your command:
Note: If you add
use Redis; on the command file, it will lead to errors, because it can't be called statically.
Now in the
handle() method of this command, add this line:
Register this command in
protected $commands = ... '\App\Console\Commands\FlushRedis', ;
Now you can simply run this command in the future to clear all the jobs from Redis (and Horizon):
php artisan flush:redis
This should be the output: