|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
|
6
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
9
|
|
|
use Symfony\Component\Config\FileLocator; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
11
|
|
|
|
|
12
|
|
|
class DtcQueueExtension extends Extension |
|
13
|
|
|
{ |
|
14
|
4 |
|
public function load(array $configs, ContainerBuilder $container) |
|
15
|
|
|
{ |
|
16
|
4 |
|
$processor = new Processor(); |
|
17
|
4 |
|
$configuration = new Configuration(); |
|
18
|
|
|
|
|
19
|
4 |
|
$config = $processor->processConfiguration($configuration, $configs); |
|
20
|
4 |
|
$this->configBeanstalkd($config, $container); |
|
21
|
4 |
|
$this->configRabbitMQ($config, $container); |
|
22
|
|
|
$this->configRedis($config, $container); |
|
23
|
4 |
|
|
|
24
|
4 |
|
$container->setParameter('dtc_queue.manager.job', $config['manager']['job']); |
|
25
|
4 |
|
$container->setParameter('dtc_queue.odm.document_manager', $config['odm']['document_manager']); |
|
26
|
4 |
|
$container->setParameter('dtc_queue.orm.entity_manager', $config['orm']['entity_manager']); |
|
27
|
4 |
|
$container->setParameter('dtc_queue.manager.run', isset($config['manager']['run']) ? $config['manager']['run'] : $config['manager']['job']); |
|
28
|
4 |
|
$container->setParameter('dtc_queue.manager.job_timing', isset($config['manager']['job_timing']) ? $config['manager']['job_timing'] : $container->getParameter('dtc_queue.manager.run')); |
|
29
|
4 |
|
$container->setParameter('dtc_queue.priority.direction', $config['priority']['direction']); |
|
30
|
4 |
|
$container->setParameter('dtc_queue.priority.max', $config['priority']['max']); |
|
31
|
4 |
|
$container->setParameter('dtc_queue.retry.max.retries', $config['retry']['max']['retries']); |
|
32
|
|
|
$container->setParameter('dtc_queue.retry.max.failures', $config['retry']['max']['failures']); |
|
33
|
|
|
$container->setParameter('dtc_queue.retry.max.exceptions', $config['retry']['max']['exceptions']); |
|
34
|
4 |
|
$container->setParameter('dtc_queue.retry.max.stalls', $config['retry']['max']['stalls']); |
|
35
|
|
|
$container->setParameter('dtc_queue.retry.auto.failure', $config['retry']['auto']['failure']); |
|
36
|
4 |
|
$container->setParameter('dtc_queue.retry.auto.exception', $config['retry']['auto']['exception']); |
|
37
|
4 |
|
$this->configClasses($config, $container); |
|
38
|
|
|
$this->configRecordTimings($config, $container); |
|
39
|
4 |
|
$this->configAdmin($config, $container); |
|
40
|
|
|
|
|
41
|
4 |
|
// Load Grid if Dtc\GridBundle Bundle is registered |
|
42
|
4 |
|
$yamlLoader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
43
|
|
|
|
|
44
|
4 |
|
$yamlLoader->load('queue.yml'); |
|
45
|
|
|
} |
|
46
|
4 |
|
|
|
47
|
4 |
|
protected function configDeprecated(array $config, ContainerBuilder $container) |
|
48
|
4 |
|
{ |
|
49
|
4 |
|
if (isset($config['default_manager'])) { |
|
50
|
4 |
|
$container->setParameter('dtc_queue.manager.job', $config['default_manager']); |
|
51
|
4 |
|
} |
|
52
|
|
|
if (isset($config['run_manager'])) { |
|
53
|
4 |
|
$container->setParameter('dtc_queue.manager.run', $config['run_manager']); |
|
54
|
|
|
} |
|
55
|
4 |
|
if (isset($config['job_timing_manager'])) { |
|
56
|
4 |
|
$container->setParameter('dtc_queue.manager.run', $config['job_timing_manager']); |
|
57
|
4 |
|
} |
|
58
|
|
|
if (isset($config['document_manager'])) { |
|
59
|
|
|
$container->setParameter('dtc_queue.odm.document_manager', $config['document_manager']); |
|
60
|
4 |
|
} |
|
61
|
|
|
if (isset($config['entity_manager'])) { |
|
62
|
4 |
|
$container->setParameter('dtc_queue.odm.entity_manager', $config['entity_manager']); |
|
63
|
|
|
} |
|
64
|
4 |
|
if (isset($config['class_job'])) { |
|
65
|
1 |
|
$container->setParameter('dtc_queue.class.job', $config['class_job']); |
|
66
|
1 |
|
} |
|
67
|
1 |
|
if (isset($config['class_job_archive'])) { |
|
68
|
|
|
$container->setParameter('dtc_queue.class.job_archive', $config['class_job_archive']); |
|
69
|
|
|
} |
|
70
|
1 |
|
if (isset($config['class_run'])) { |
|
71
|
1 |
|
$container->setParameter('dtc_queue.class.run', $config['class_run']); |
|
72
|
|
|
} |
|
73
|
4 |
|
if (isset($config['class_run_archive'])) { |
|
74
|
|
|
$container->setParameter('dtc_queue.class.run_archive', $config['class_run_archive']); |
|
75
|
4 |
|
} |
|
76
|
|
|
if (isset($config['class_job_timing'])) { |
|
77
|
4 |
|
$container->setParameter('dtc_queue.class.job_timing', $config['class_job_timing']); |
|
78
|
1 |
|
} |
|
79
|
1 |
|
if (isset($config['record_timings'])) { |
|
80
|
|
|
$container->setParameter('dtc_queue.timings.record', $config['record_timings']); |
|
81
|
|
|
} |
|
82
|
|
|
if (isset($config['record_timings_timezone_offset'])) { |
|
83
|
4 |
|
$container->setParameter('dtc_queue.timings.timezone_offset', $config['record_timings_timezone_offset']); |
|
84
|
1 |
|
} |
|
85
|
|
|
if (isset($config['record_timings_timezone_offset'])) { |
|
86
|
4 |
|
$container->setParameter('dtc_queue.timings.timezone_offset', $config['record_timings_timezone_offset']); |
|
87
|
1 |
|
} |
|
88
|
|
|
if (isset($config['priority_max'])) { |
|
89
|
4 |
|
$container->setParameter('dtc_queue.priority.max', $config['priority_max']); |
|
90
|
|
|
} |
|
91
|
1 |
|
if (isset($config['priority_direction'])) { |
|
92
|
|
|
$container->setParameter('dtc_queue.priority.direction', $config['priority_direction']); |
|
93
|
1 |
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
protected function configRedis(array $config, ContainerBuilder $container) |
|
97
|
|
|
{ |
|
98
|
|
|
$container->setParameter('dtc_queue.redis.prefix', $config['redis']['prefix']); |
|
99
|
|
|
if (isset($config['redis']['snc_redis']['type'])) { |
|
100
|
|
|
$container->setParameter('dtc_queue.redis.snc_redis.type', $config['redis']['snc_redis']['type']); |
|
101
|
|
|
$container->setParameter('dtc_queue.redis.snc_redis.alias', $config['redis']['snc_redis']['alias']); |
|
102
|
|
|
} elseif (isset($config['redis']['predis']['dsn'])) { |
|
103
|
|
|
$container->setParameter('dtc_queue.redis.predis.dsn', $config['redis']['predis']['dsn']); |
|
104
|
|
|
} elseif (isset($config['redis']['predis']['connection_parameters']['host'])) { |
|
105
|
|
|
$container->setParameter('dtc_queue.redis.predis.connection_parameters', $config['redis']['predis']['connection_parameters']); |
|
106
|
|
|
} elseif (isset($config['redis']['phpredis']['host'])) { |
|
107
|
|
|
$container->setParameter('dtc_queue.redis.phpredis', $config['redis']['phpredis']); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
protected function configAdmin(array $config, ContainerBuilder $container) |
|
112
|
|
|
{ |
|
113
|
|
|
$container->setParameter('dtc_queue.admin.chartjs', $config['admin']['chartjs']); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
protected function configClasses(array $config, ContainerBuilder $container) |
|
117
|
|
|
{ |
|
118
|
|
|
$container->setParameter('dtc_queue.class.job', isset($config['class']['job']) ? $config['class']['job'] : null); |
|
119
|
|
|
$container->setParameter('dtc_queue.class.job_archive', isset($config['class']['job_archive']) ? $config['class']['job_archive'] : null); |
|
120
|
|
|
$container->setParameter('dtc_queue.class.run', isset($config['class']['run']) ? $config['class']['run'] : null); |
|
121
|
|
|
$container->setParameter('dtc_queue.class.run_archive', isset($config['class']['run_archive']) ? $config['class']['run_archive'] : null); |
|
122
|
|
|
$container->setParameter('dtc_queue.class.job_timing', isset($config['class']['job_timing']) ? $config['class']['job_timing'] : null); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
protected function configRecordTimings(array $config, ContainerBuilder $container) |
|
126
|
|
|
{ |
|
127
|
|
|
$container->setParameter('dtc_queue.timings.record', isset($config['timings']['record']) ? $config['timings']['record'] : false); |
|
128
|
|
|
$container->setParameter('dtc_queue.timings.timezone_offset', $config['timings']['timezone_offset']); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
protected function configRabbitMQ(array $config, ContainerBuilder $container) |
|
132
|
|
|
{ |
|
133
|
|
|
if (isset($config['rabbit_mq'])) { |
|
134
|
|
|
foreach (['host', 'port', 'user', 'password'] as $value) { |
|
135
|
|
|
if (!isset($config['rabbit_mq'][$value])) { |
|
136
|
|
|
throw new InvalidConfigurationException('dtc_queue: rabbit_mq must have '.$value.' in config.yml'); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
$config['rabbit_mq']['queue_args']['max_priority'] = $config['priority']['max']; |
|
140
|
|
|
$container->setParameter('dtc_queue.rabbit_mq', $config['rabbit_mq']); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
protected function configBeanstalkd(array $config, ContainerBuilder $container) |
|
145
|
|
|
{ |
|
146
|
|
|
if (isset($config['beanstalkd'])) { |
|
147
|
|
|
if (!isset($config['beanstalkd']['host'])) { |
|
148
|
|
|
throw new InvalidConfigurationException('dtc_queue: beanstalkd requires host in config.yml'); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
if (isset($config['beanstalkd']['host'])) { |
|
153
|
|
|
$container->setParameter('dtc_queue.beanstalkd.host', $config['beanstalkd']['host']); |
|
154
|
|
|
} |
|
155
|
|
|
if (isset($config['beanstalkd']['tube'])) { |
|
156
|
|
|
$container->setParameter('dtc_queue.beanstalkd.tube', $config['beanstalkd']['tube']); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function getAlias() |
|
161
|
|
|
{ |
|
162
|
|
|
return 'dtc_queue'; |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|