-
-
Save lukaswhite/8882024 to your computer and use it in GitHub Desktop.
<?php | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
class ClearBeanstalkdQueueCommand extends Command { | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'queue:beanstalkd:clear'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Clear a Beanstalkd queue, by deleting all pending jobs.'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Defines the arguments. | |
* | |
* @return array | |
*/ | |
public function getArguments() | |
{ | |
return array( | |
array('queue', InputArgument::OPTIONAL, 'The name of the queue to clear.'), | |
); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return void | |
*/ | |
public function fire() | |
{ | |
$queue = ($this->argument('queue')) ? $this->argument('queue') : Config::get('queue.connections.beanstalkd.queue'); | |
$this->info(sprintf('Clearing queue: %s', $queue)); | |
$pheanstalk = Queue::getPheanstalk(); | |
$pheanstalk->useTube($queue); | |
$pheanstalk->watch($queue); | |
while ($job = $pheanstalk->reserve(0)) { | |
$pheanstalk->delete($job); | |
} | |
$this->info('...cleared.'); | |
} | |
} |
This also saved my life, this afternoon. :)
I am getting this error when running php artisan queue:beanstalkd:clear
[InvalidArgumentException]
There are no commands defined in the "queue:beanstalkd" namespace.
Did you mean this?
queue
@jfhernandeze You need to register the command in your app/start/artisan.php file:
Artisan::add(new ClearBeanstalkdQueueCommand);
I've made a composer package for this to help anyone else out - https://github.com/morrislaptop/laravel-queue-clear
This is awesome!
Just to be clear, the Gist above by @lukaswhite is for Laravel 4 and the package by @morrislaptop is for Laravel 5.
Life saver :)
THANK YOUUUUUUU
I don't know if this will help anyone. Delete a specific job from beanstalk for laravel 4.
$res = Queue::getPheanstalk();
$job = $res->peek(29); //29 is the job id i want to delete
$res->delete($job);
I've posted my implementation for Laravel 5.1 https://gist.github.com/cheelahim/ded1ab9e5e9a290fe9fc
Thanks so much!!
Awesome, thanks!
Awesome, thanks!
Great! 👍
thanks
thanks 👍
Thank you!
thank you. this saved my life this morning.