1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gendoria\CommandQueueRabbitMqDriverBundle\Worker; |
4
|
|
|
|
5
|
|
|
use Gendoria\CommandQueue\Worker\WorkerRunnerInterface; |
6
|
|
|
use InvalidArgumentException; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
8
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
9
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
12
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Description of RabbitMqWorkerRunner |
16
|
|
|
* |
17
|
|
|
* @author Tomasz Struczyński <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class RabbitMqWorkerRunner implements WorkerRunnerInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Container. |
23
|
|
|
* |
24
|
|
|
* @var ContainerInterface |
25
|
|
|
*/ |
26
|
|
|
private $container; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Set container. |
30
|
|
|
* |
31
|
|
|
* @param ContainerInterface $container |
32
|
|
|
*/ |
33
|
3 |
|
public function setContainer(ContainerInterface $container) |
34
|
|
|
{ |
35
|
3 |
|
$this->container = $container; |
36
|
3 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get container. |
40
|
|
|
* |
41
|
|
|
* @return ContainerInterface|null |
42
|
|
|
*/ |
43
|
1 |
|
public function getContainer() |
44
|
|
|
{ |
45
|
1 |
|
return $this->container; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
3 |
|
public function run(array $options, OutputInterface $output = null) |
52
|
|
|
{ |
53
|
3 |
|
if (empty($options['consumer_name'])) { |
54
|
1 |
|
throw new InvalidArgumentException("Options array has to contain consumer_name."); |
55
|
|
|
} |
56
|
2 |
|
if (!$output) { |
57
|
2 |
|
$output = new NullOutput(); |
58
|
2 |
|
} |
59
|
|
|
/* @var $kernel \Symfony\Component\HttpKernel\KernelInterface */ |
60
|
2 |
|
$kernel = $this->container->get('kernel'); |
61
|
2 |
|
$application = new Application($kernel); |
62
|
2 |
|
$application->setAutoExit(false); |
63
|
2 |
|
$input = new ArrayInput(array( |
64
|
2 |
|
'command' => 'rabbitmq:consumer', |
65
|
2 |
|
'-w' => null, |
66
|
2 |
|
'name' => !empty($options['reschedule']) ? $options['consumer_name'].'_reschedule_delayed' : $options['consumer_name'], |
67
|
2 |
|
)); |
68
|
2 |
|
$application->run($input, $output); |
69
|
2 |
|
} |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|