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

RunWorkerCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 2
crap 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