Skip to content

Commit

Permalink
Update virge-cli version
Browse files Browse the repository at this point in the history
  • Loading branch information
siosphere committed Apr 11, 2017
1 parent 69b10a7 commit 4d6d965
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
21 changes: 15 additions & 6 deletions Virge/Graphite/Command/SupervisorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
namespace Virge\Graphite\Command;

use Virge\Cli;
use Virge\Cli\Component\Command;
use Virge\Cli\Component\Process;
use Virge\Cli\Component\{
Command,
Input,
Process
};
use Virge\Core\Config;
use Virge\Graphite\Component\Task;
use Virge\Graphite\Service\QueueService;
Expand All @@ -16,18 +19,24 @@
*/
class SupervisorCommand extends Command
{

const COMMAND = 'virge:graphite:supervisor';
const COMMAND_HELP = 'Start a number of workers against a given queue';
const COMMAND_USAGE = 'virge:graphite:supervisor <queueName> <totalWorkers>';


protected $queueName;
protected $workers = [];
protected $totalWorkers = 3;
protected $queueUpCommand = "virge:graphite:worker";

public function run($queueName = 'graphite_queue', $totalWorkers = 3)
public function run(Input $input)
{

$queueName = $input->getArgument(0) ?? 'graphite_queue';
$totalWorkers = $input->getArgument(1) ?? 3;

if($this->instanceAlreadyRunning([$queueName])) {
$this->terminate();
Cli::error('Instance already running');
$this->terminate(-1);
}
$this->totalWorkers = $totalWorkers;
$this->queueName = $queueName;
Expand Down
15 changes: 13 additions & 2 deletions Virge/Graphite/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
namespace Virge\Graphite\Command;

use Virge\Cli;
use Virge\Cli\Component\{
Command,
Input
};
use Virge\Graphite\Component\Task;
use Virge\Graphite\Service\QueueService;
use Virge\Graphite\Worker;
Expand All @@ -11,11 +15,18 @@
*
* @author Michael Kramer
*/
class WorkerCommand {
class WorkerCommand extends Command
{

const COMMAND = 'virge:graphite:worker';
const COMMAND_HELP = 'Worker that will process the given queue';
const COMMAND_USAGE = 'virge:graphite:worker <queueName>';

public function run($queueName = 'graphite_queue') {
public function run(Input $input) {
$queueName = $input->getArgument(0) ?? 'graphite_queue';

Cli::important(sprintf("Started worker for: " . $queueName));

$this->getQueueService()->listen($queueName, function(Task $task) {
//dispatch this task
Worker::dispatch($task);
Expand Down
10 changes: 8 additions & 2 deletions Virge/Graphite/config/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
use Virge\Graphite\Command\WorkerCommand;
use Virge\Graphite\Command\SupervisorCommand;

Cli::add(WorkerCommand::COMMAND, new WorkerCommand(), 'run');
Cli::add(SupervisorCommand::COMMAND, new SupervisorCommand(), 'run');
Cli::add(WorkerCommand::COMMAND, new WorkerCommand(), 'run')
->setHelpText(WorkerCommand::COMMAND_HELP)
->setUsage(WorkerCommand::COMMAND_USAGE)
;
Cli::add(SupervisorCommand::COMMAND, new SupervisorCommand(), 'run')
->setHelpText(SupervisorCommand::COMMAND_HELP)
->setUsage(SupervisorCommand::COMMAND_USAGE)
;
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "virge/graphite",
"require-dev": {
"virge/core": "~1.0",
"virge/cli": "~2.0",
"virge/cli": "~3.0",
"virge/db": "~2.0"
},
"autoload": {
Expand Down

0 comments on commit 4d6d965

Please sign in to comment.