-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathConfiguration.php
More file actions
237 lines (208 loc) · 10.4 KB
/
Copy pathConfiguration.php
File metadata and controls
237 lines (208 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
namespace Dtc\QueueBundle\DependencyInjection;
use Dtc\QueueBundle\Manager\PriorityJobManager;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
use RabbitMQConfiguration;
use RedisConfiguration;
/**
* Generates the configuration tree.
*
* @return TreeBuilder
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('dtc_queue');
$rootNode = $treeBuilder->getRootNode();
$node = $rootNode
->children()
->booleanNode('locale_fix')
->defaultFalse()
->info('Set this to true to fix issues with ORM saving (see issue #98) in non-period decimal format locales')
->end()
->append($this->addSimpleScalar('orm', 'entity_manager', 'This only needs to be set if orm is used for any of the managers, and you do not want to use the default entity manager'))
->append($this->addSimpleScalar('odm', 'document_manager', 'This only needs to be set if odm is used for any of the managers, and you do not want to use the default document manager'))
->append($this->addManager())
->append($this->addTimings())
->append($this->addBeanstalkd())
->append($this->addRabbitMq())
->append($this->addRedis())
->append($this->addSimpleScalar('admin', 'chartjs', 'This can be changed to say a locally hosted path or url.', 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.min.js'))
->append($this->addClasses())
->append($this->addPriority())
->append($this->addRetry());
$node = $this->setDeprecatedNode($node, 'scalarNode', 'document_manager', 'The "%node% option is deprecated, Use "odm: { document_manager: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'entity_manager', 'The "%node% option is deprecated, Use "orm: { entity_manager: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'default_manager', 'The "%node% option is deprecated, Use "manager: { job: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'run_manager', 'The "%node% option is deprecated, Use "manager: { run: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'job_timing_manager', 'The "%node% option is deprecated, Use "manager: { job_timing: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'booleanNode', 'record_timings', 'The "%node% option is deprecated, Use "timings: { record: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'floatNode', 'record_timings_timezone_offset', 'The "%node% option is deprecated, Use "record: { timezone_offset: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job', 'The "%node% option is deprecated, Use "class: { job: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job_archive', 'The "%node% option is deprecated, Use "class: { job_archive: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'class_run', 'The "%node% option is deprecated, Use "class: { run: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'class_run_archive', 'The "%node% option is deprecated, Use "class: { run_archive: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job_timing', 'The "%node% option is deprecated, Use "class: { job_timing: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'priority_max', 'The "%node% option is deprecated, Use "priority: { max: ... }" instead.');
$node = $this->setDeprecatedNode($node, 'scalarNode', 'priority_direction', 'The "%node% option is deprecated, Use "priority: { direction: ... }" instead.');
$node->end();
return $treeBuilder;
}
public function setDeprecatedNode($node, $type, $name, $deprecatedMessage)
{
$node = $node->$type($name);
$node = $node->setDeprecated('mmucklo/queue-bundle', '5.1', $deprecatedMessage);
return $node->end();
}
protected function addTimings()
{
$treeBuilder = new TreeBuilder('timings');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->addDefaultsIfNotSet()
->children()
->booleanNode('record')
->info('Set this to true to record timings (used on the Trends page)')
->defaultFalse()
->end()
->floatNode('timezone_offset')
->defaultValue(0)
->info('Set this some integer offset from GMT in case your database is not storing things in the proper timezone and the dates look off on the Trends page')
->max(24)
->min(-24)
->end()
->end();
return $rootNode;
}
protected function addSimpleScalar($rootName, $nodeName, $info, $defaultValue = 'default')
{
$treeBuilder = new TreeBuilder($rootName);
$rootNode = $treeBuilder->getRootNode();
$rootNode
->addDefaultsIfNotSet()
->children()
->scalarNode($nodeName)
->info($info)
->defaultValue($defaultValue)
->cannotBeEmpty()
->end()
->end();
return $rootNode;
}
protected function addManager()
{
$treeBuilder = new TreeBuilder('manager');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->addDefaultsIfNotSet()
->children()
->scalarNode('job')
->defaultValue('odm')
->info('This can be [odm|orm|beanstalkd|rabbit_mq|redis|(your-own-custom-one)]')
->cannotBeEmpty()
->end()
->scalarNode('run')->end()
->scalarNode('job_timing')->end()
->end();
return $rootNode;
}
protected function addBeanstalkd()
{
$treeBuilder = new TreeBuilder('beanstalkd');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->children()
->scalarNode('host')->end()
->integerNode('port')
->defaultValue(11300)
->end()
->scalarNode('tube')->end()
->end();
return $rootNode;
}
protected function addRetry()
{
$treeBuilder = new TreeBuilder('retry');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->addDefaultsIfNotSet()
->children()
->arrayNode('max')
->addDefaultsIfNotSet()
->children()
->integerNode('retries')
->info('This the maximum total number of retries of any type.')
->defaultValue(3)
->end()
->integerNode('failures')
->info('This the maximum total number of failures before a job is marked as hitting the maximum failures.')
->defaultValue(1)
->end()
->integerNode('exceptions')
->info('This the maximum total number of exceptions before a job is marked as hitting the maximum exceptions.')
->defaultValue(2)
->end()
->integerNode('stalls')
->info('This the maximum total number of exceptions before a job is marked as hitting the maximum exceptions.')
->defaultValue(2)
->end()
->end()
->end()
->arrayNode('auto')
->addDefaultsIfNotSet()
->children()
->booleanNode('failure')
->info('Instantly re-queue the job on failure.')
->defaultTrue()
->end()
->booleanNode('exception')
->info('Instantly re-queue the job on exception.')
->defaultFalse()
->end()
->end()
->end()
->end();
return $rootNode;
}
protected function addPriority()
{
$treeBuilder = new TreeBuilder('priority');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->addDefaultsIfNotSet()
->children()
->integerNode('max')
->defaultValue(255)
->info('Maximum priority value.')
->min(1)
->end()
->enumNode('direction')
->values([PriorityJobManager::PRIORITY_ASC, PriorityJobManager::PRIORITY_DESC])
->info('Whether 1 is high priority or low prioirty. '.PriorityJobManager::PRIORITY_ASC.' means 1 is low, '.PriorityJobManager::PRIORITY_DESC.' means 1 is high.')
->defaultValue(PriorityJobManager::PRIORITY_DESC)
->end()
->end();
return $rootNode;
}
protected function addClasses()
{
$treeBuilder = new TreeBuilder('class');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->children()
->scalarNode('job')
->info('If you want to override the Job class, put the class name here.')->end()
->scalarNode('job_archive')
->info('If you want to override the JobArchive class, put the class name here.')->end()
->scalarNode('job_timing')
->info('If you want to override the JobTiming class, put the class name here.')->end()
->scalarNode('run')
->info('If you want to override the Run class, put the class name here.')->end()
->scalarNode('run_archive')
->info('If you want to override the RunArchive class, put the class name here.')->end()
->end();
return $rootNode;
}
}