@@ -44,6 +44,11 @@ class RabbitMqSupervisor
44
44
*/
45
45
private $ workerCount ;
46
46
47
+ /**
48
+ * @var array
49
+ */
50
+ private $ workerOptions ;
51
+
47
52
/**
48
53
* Initialize Handler
49
54
*
@@ -54,8 +59,9 @@ class RabbitMqSupervisor
54
59
* @param array $consumers
55
60
* @param array $multipleConsumers
56
61
* @param int $workerCount
62
+ * @param array $workerOptions
57
63
*/
58
- public function __construct (Supervisor $ supervisor , EngineInterface $ templating , array $ paths , array $ commands , $ consumers , $ multipleConsumers , $ workerCount )
64
+ public function __construct (Supervisor $ supervisor , EngineInterface $ templating , array $ paths , array $ commands , $ consumers , $ multipleConsumers , $ workerCount, array $ workerOptions = array () )
59
65
{
60
66
$ this ->supervisor = $ supervisor ;
61
67
$ this ->templating = $ templating ;
@@ -64,6 +70,7 @@ public function __construct(Supervisor $supervisor, EngineInterface $templating,
64
70
$ this ->consumers = $ consumers ;
65
71
$ this ->multipleConsumers = $ multipleConsumers ;
66
72
$ this ->workerCount = $ workerCount ;
73
+ $ this ->workerOptions = $ workerOptions ;
67
74
}
68
75
69
76
/**
@@ -271,13 +278,7 @@ private function generateWorkerConfigurations($names, $command, $maxMessages = 2
271
278
'workerOutputLog ' => $ this ->paths ['worker_output_log_file ' ],
272
279
'workerErrorLog ' => $ this ->paths ['worker_error_log_file ' ],
273
280
'numprocs ' => $ this ->workerCount ,
274
- 'options ' => array (
275
- 'startsecs ' => '2 ' ,
276
- 'autorestart ' => 'true ' ,
277
- 'stopsignal ' => 'INT ' ,
278
- 'stopasgroup ' => 'true ' ,
279
- 'stopwaitsecs ' => '60 ' ,
280
- )
281
+ 'options ' => $ this ->transformBoolsToStrings ($ this ->workerOptions ),
281
282
)
282
283
);
283
284
}
@@ -303,4 +304,25 @@ private function createSupervisorConfigurationFilePath()
303
304
{
304
305
return $ this ->paths ['configuration_file ' ];
305
306
}
307
+
308
+ /**
309
+ * Transform bool array values to string representation.
310
+ *
311
+ * @param array $options
312
+ *
313
+ * @return array
314
+ */
315
+ private function transformBoolsToStrings (array $ options )
316
+ {
317
+ $ transformedOptions = array ();
318
+ foreach ($ options as $ key => $ value ) {
319
+ if (is_bool ($ value )) {
320
+ $ value = $ value ? 'true ' : 'false ' ;
321
+ }
322
+
323
+ $ transformedOptions [$ key ] = $ value ;
324
+ }
325
+
326
+ return $ transformedOptions ;
327
+ }
306
328
}
0 commit comments