Completed
Push — master ( 8d8ba2...657761 )
by Tomasz
03:53
created

RunWorkerCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 21
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A execute() 0 11 2
1
<?php
2
3
namespace Gendoria\CommandQueueBundle\Command;
4
5
use Gendoria\CommandQueueBundle\Worker\WorkerRunnerManager;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Description of RunWorkerCommand
13
 *
14
 * @author Tomasz Struczyński <[email protected]>
15
 */
16
class RunWorkerCommand extends ContainerAwareCommand
17
{
18 2
    protected function configure()
19
    {
20 2
        $this->setName('command-queue:worker')
21 2
            ->setDescription('Runs a worker process. Specific worker has to be registered by driver or application.')
22 2
            ->addArgument('name', InputArgument::REQUIRED, 'Worker name.');
23 2
    }
24
    
25 2
    public function execute(InputInterface $input, OutputInterface $output)
26
    {
27 2
        $name = $input->getArgument('name');
28
        /* @var $workerRunnerService WorkerRunnerManager */
29 2
        $workerRunnerService = $this->getContainer()->get('gendoria_command_queue.runner_manager');
30 2
        if (!$workerRunnerService->has($name)) {
31 1
            $output->writeln(sprintf('<error>Worker "%s" not registered.</error>', $name));
32 1
            return 1;
33
        }
34 1
        $workerRunnerService->run($name, $output);
35 1
    }
36
}
37