Completed
Pull Request — master (#2)
by Wachter
03:33
created

RunHandlerCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 2
Metric Value
c 2
b 1
f 2
dl 0
loc 11
rs 9.4286
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
namespace Task\TaskBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Task\Handler\RegistryInterface;
10
use Task\SchedulerInterface;
11
12
/**
13
 * Run pending tasks.
14
 *
15
 * @author Alexander Schranz <[email protected]>
16
 */
17
class RunHandlerCommand extends Command
18
{
19
    /**
20
     * @var RegistryInterface
21
     */
22
    private $registry;
23
24
    public function __construct(RegistryInterface $registry)
25
    {
26
        parent::__construct('task:run:handler');
27
28
        $this->registry = $registry;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    protected function configure()
35
    {
36
        $this->setDescription('Run pending tasks')
37
            ->addArgument('handler', InputArgument::REQUIRED)
38
            ->addArgument('workload', InputArgument::OPTIONAL);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46
        $handler = $input->getArgument('handler');
47
        $workload = $input->getArgument('workload');
48
49
        $output->writeln(sprintf('Run command "%s" with workload "%s"', $handler, $workload));
50
51
        $result = $this->registry->run($handler, $workload);
52
53
        $output->writeln(sprintf('Result: "%s"', $result));
54
    }
55
}
56