Completed
Push — master ( 657761...4271e2 )
by Tomasz
05:00
created

RunWorkerCommand::formatRunnerName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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
            $runners = $workerRunnerService->getRunners();
32 1
            $runnersFormatted = array_map(array($this, 'formatRunnerName'), $runners);
33 1
            $output->writeln(sprintf('<error>Worker "%s" not registered.</error>', $name));
34 1
            $output->writeln('Registered workers:');
35 1
            $output->writeln($runnersFormatted);
36 1
            return 1;
37
        }
38 1
        $workerRunnerService->run($name, $output);
39 1
    }
40
    
41 1
    public function formatRunnerName($name)
42
    {
43 1
        return sprintf("  * <info>%s</info>", $name);
44
    }
45
}
46