ConsumeCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace Workana\AsyncJobs\Console;
3
4
use Workana\AsyncJobs\JobManager;
5
use Workana\AsyncJobs\EventListener\ConsoleSubscriber;
6
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Command for job consuming
14
 *
15
 * @author Carlos Frutos <[email protected]>
16
 */
17
class ConsumeCommand extends Command
18
{
19
    /**
20
     * @var JobManager
21
     */
22
    protected $jm;
23
24
    /**
25
     * Creates a new Command
26
     *
27
     * @param JobManager $jm
28
     */
29
    public function __construct(JobManager $jm)
30
    {
31
        parent::__construct('consume');
32
33
        $this->jm = $jm;
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    public function configure()
40
    {
41
        $this->setDescription('Consume queues')
42
                ->addOption(
43
                'queues',
44
                null,
45
                InputOption::VALUE_REQUIRED,
46
                'Comma separated names of one or more queues that will be consumed.'
47
            );
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function execute(InputInterface $input, OutputInterface $output)
54
    {
55
        $this->jm->getEventDispatcher()->addSubscriber(new ConsoleSubscriber($output));
56
57
        $queues = array_map('trim', explode(',', $input->getOption('queues')));
58
59
        $worker = $this->jm->createWorkerBuilder()->usingMultipleQueues($queues)->build();
60
        $worker->run();
61
    }
62
}