Deleting queued jobs in laravel

Claire picture Claire · Dec 10, 2013 · Viewed 43.2k times · Source

I have added some jobs to a queue in Laravel. However, I forgot to put $job->delete() in the function and there is an error in my function. This means the job is never ending. It keeps going being replaced onto the queue and keeps erroring in my log file. How can I delete it from the command line?

I am using beanstalkd for my queuing.

Answer

DutGRIFF picture DutGRIFF · Aug 28, 2014

I am using Redis instead of Beanstalkd but this should be the same in both. Restarting Redis doesn't solve the problem. I looked at RedisQueues in the Laravel 4.2 API Docs and found:

public Job|null pop(string $queue = null)
  //Pop the next job off of the queue.

This is the same if you look at BeanstalkedQueue.

I threw it in app/routes.php inside dd*, loaded that page and voila.

Route::get('/', function() {
  dd(Queue::pop());
  #return View::make('hello');
});

NOTE: Reload the page once per queue.

The queue was pulled off the stack. I would like to see a cleaner solution but this worked for me more than once.

*dd($var) = Laravel's die and dump function = die(var_dump($var))

Edit 1: For Redis

The above obviously isn't the best solution so here is a better way. Be careful!

FLUSHDB - Delete all the keys of the currently selected DB. This command never fails.

For Redis use FLUSHDB. This will flush the Redis database not Laravel's database. In the terminal:

$ redis-cli
127.0.0.1:6379> FLUSHDB
OK
127.0.0.1:6379> exit