11

I have a production system on AWS and use Laravel Forge. There is a single default queue that is processing Jobs.

I've created a number jobs and now wish to delete them (as they take many hours to complete and I realize my input data was bad). I created a new job with good data, but it won't be processed until all the others have finished.

How can I delete all jobs?

It was previously set up using redis queue driver. I could not figure out how to delete jobs, so I switched the driver to database, and restarted the server, thinking that this would at least get the jobs to stop processing. However, much to my dismay, they continue to be processed :-(

I even deleted the worker from the forge ui and restarted the server: the jobs still process.

Why do jobs continue to be processed?

How can I stop them?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
BizzyBob
  • 12,309
  • 4
  • 27
  • 51

2 Answers2

22

You can use:

php artisan queue:clear redis

It will clear all jobs from default queue on redis connection. If you put jobs in other queue then you should specify queue name for example:

php artisan queue:clear redis --queue=custom_queue_name
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • 6
    Thank you but `queue:clear` seems to be available only in Laravel 8. – BizzyBob Feb 16 '21 at 17:27
  • Sorry, that's indeed true. So probably there is no ready way. But you can for example update implementation of queue jobs to finish their jobs just in second (so they won't really do anything) or you can maybe port needed part ofhttps://github.com/laravel/framework/pull/34330/files to your app. – Marcin Nabiałek Feb 16 '21 at 17:50
  • That could work. Any ideas why jobs continue to execute after switching from redis to database? Seems like that would result in effectively having 0 jobs. If I use database, I can easily remove jobs. – BizzyBob Feb 16 '21 at 17:54
  • @BizzyBob When you updated `.env`, have you run also `php artisan config:cache` (assuming you have cached configuration) and after that restarted queue worker? – Marcin Nabiałek Feb 16 '21 at 17:58
  • I tried clearing config cache and restarting entire server. Job is still running. :-o – BizzyBob Feb 16 '21 at 18:08
  • If I create new job, I see it gets created in database now. – BizzyBob Feb 16 '21 at 18:09
  • Thanks for your help. It seems I have 2 workers running, although only 1 is configured. I posted a [new question](https://stackoverflow.com/questions/66230137/laravel-forge-worker-process-keeps-getting-re-created) with relevant details. – BizzyBob Feb 16 '21 at 18:29
  • I wonder where `queue:clear` comes from... I can see only [`queue:flush`](https://github.com/laravel/framework/tree/v8.82.0/src/Illuminate/Queue/Console) (and `queue:forget` for a single job). **UPD** My bad, available since `8.4.0`. – x-yuri Feb 07 '22 at 17:59
0

queue:clear only exists since version 8x of laravel and the command queue:flush only deletes failed jobs.

php artisan queue:flush returns:

All failed jobs deleted successfully!

So, if you want to delete all the queue jobs, go to your database table "jobs" and delete them manually.

Linesofcode
  • 5,327
  • 13
  • 62
  • 116