Skip to content

Commit

Permalink
Added resque:listen artisan command
Browse files Browse the repository at this point in the history
  • Loading branch information
fonse committed Sep 2, 2013
1 parent 0730c61 commit 4ecee16
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/Awellis13/Resque/Console/ListenCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php namespace Awellis13\Resque\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Config;
use Resque;
use Resque_Worker;

class ListenCommand extends Command {

/**
* The console command name.
*
* @var string
*/
protected $name = 'resque:listen';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Run a resque worker';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
// Read input
$logLevel = $this->input->getOption('verbose') ? Resque_Worker::LOG_NORMAL : 0;
$queue = $this->input->getOption('queue');
$interval = $this->input->getOption('interval');

// Connect to redis
Resque::setBackend(Config::get('database.redis.default.host').':'.Config::get('database.redis.default.port'));

// Launch worker
$queues = explode(',', $queue);
$worker = new Resque_Worker($queues);
$worker->logLevel = $logLevel;

fwrite(STDOUT, '*** Starting worker ' . $worker . "\n");
$worker->work($interval);
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('queue', null, InputOption::VALUE_OPTIONAL, 'The queue to listen on', 'default'),
array('interval', null, InputOption::VALUE_OPTIONAL, 'Amount of time to delay failed jobs', 5),
);
}

}
25 changes: 25 additions & 0 deletions src/Awellis13/Resque/ServiceProviders/ResqueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Config;
use Awellis13\Resque\Connectors\ResqueConnector;
use Awellis13\Resque\Console\ListenCommand;
use Illuminate\Queue\QueueServiceProvider;

/**
Expand All @@ -19,6 +20,14 @@ public function registerConnectors($manager)
parent::registerConnectors($manager);
$this->registerResqueConnector($manager);
}

/**
* {@inheritdoc}
*/
public function boot()
{
$this->registerCommand();
}

/**
* Register the Resque queue connector.
Expand Down Expand Up @@ -47,5 +56,21 @@ protected function registerResqueConnector($manager)
return new ResqueConnector;
});
}

/**
* Register the artisan command.
*
* @return void
*/
public function registerCommand()
{
$this->app['command.resque.listen'] = $this->app->share(
function ($app) {
return new ListenCommand();
}
);

$this->commands('command.resque.listen');
}

} // End ResqueServiceProvider

0 comments on commit 4ecee16

Please sign in to comment.