Skip to content

Instantly share code, notes, and snippets.

@arenowebdev
Created April 1, 2016 05:04
Show Gist options
  • Save arenowebdev/afadf19282537f3608fdca10f825e666 to your computer and use it in GitHub Desktop.
Save arenowebdev/afadf19282537f3608fdca10f825e666 to your computer and use it in GitHub Desktop.
Laravel Artisan command to clear Beanstalkd Queue(s)
<?php namespace App\Console\Commands;
use App\Contract\ListingsInterface;
use App\Contract\ListingCreatorInterface;
use Illuminate\Console\Command;
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.';
/**
* Defines the arguments.
*
* @return array
*/
public function getArguments()
{
return [
['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.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment