Created
December 18, 2016 12:13
-
-
Save kingpabel/8e1f9f67ed21f14ceda7f142ea49a7c8 to your computer and use it in GitHub Desktop.
Laravel 5.1 compatible command which allows to clear Beanstalkd queue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Illuminate\Queue\Connectors\BeanstalkdConnector; | |
use Pheanstalk\Pheanstalk; | |
class ClearBeanstalkdQueue extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'queue:beanstalkd:clear {queue?}'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Clear Beanstalkd queue.'; | |
/** | |
* @param BeanstalkdConnector $connector | |
*/ | |
public function handle(BeanstalkdConnector $connector) | |
{ | |
$config = config('queue.connections.beanstalkd'); | |
/** @type Pheanstalk $pheanstalk */ | |
$pheanstalk = $connector->connect($config)->getPheanstalk(); | |
$queue = $this->argument('queue') ?: $config['queue']; | |
$this->info("Clearing queue: {$queue}"); | |
$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