@@ -134,7 +134,7 @@ public function run(array $args): int {
134
134
$ startTime = time ();
135
135
136
136
while (!$ this ->exit ) {
137
- $ this ->setPhpTimeout ();
137
+ $ this ->setPhpTimeout ($ config [ ' maxruntime ' ] );
138
138
139
139
try {
140
140
$ this ->updatePid ($ pid );
@@ -167,10 +167,11 @@ public function run(array $args): int {
167
167
sleep (Config::sleeptime ());
168
168
}
169
169
170
+ $ maxRuntime = $ config ['maxruntime ' ] ?: Configure::readOrFail ('Queue.workermaxruntime ' );
170
171
// check if we are over the maximum runtime and end processing if so.
171
- if (Configure:: readOrFail ( ' Queue.workermaxruntime ' ) && (time () - $ startTime ) >= Configure:: readOrFail ( ' Queue.workermaxruntime ' ) ) {
172
+ if ($ maxRuntime && (time () - $ startTime ) >= $ maxRuntime ) {
172
173
$ this ->exit = true ;
173
- $ this ->io ->out ('Reached runtime of ' . (time () - $ startTime ) . ' Seconds (Max ' . Configure:: readOrFail ( ' Queue.workermaxruntime ' ) . '), terminating. ' );
174
+ $ this ->io ->out ('Reached runtime of ' . (time () - $ startTime ) . ' Seconds (Max ' . $ maxRuntime . '), terminating. ' );
174
175
}
175
176
if ($ this ->exit || mt_rand (0 , 100 ) > 100 - (int )Config::gcprob ()) {
176
177
$ this ->io ->out ('Performing Old job cleanup. ' );
@@ -426,13 +427,21 @@ protected function stringToArray(string $param): array {
426
427
}
427
428
428
429
/**
429
- * Makes sure accidental overriding isn't possible, uses workermaxruntime times 100 by default.
430
+ * Makes sure accidental overriding isn't possible, uses workermaxruntime times 2 by default.
430
431
* If available, uses workertimeout config directly.
431
432
*
433
+ * @param int|null $maxruntime Max runtime in seconds if set via CLI option.
434
+ *
432
435
* @return void
433
436
*/
434
- protected function setPhpTimeout (): void {
435
- $ timeLimit = (int )Configure::readOrFail ('Queue.workermaxruntime ' ) * 100 ;
437
+ protected function setPhpTimeout (?int $ maxruntime ): void {
438
+ if ($ maxruntime ) {
439
+ set_time_limit ($ maxruntime * 2 );
440
+
441
+ return ;
442
+ }
443
+
444
+ $ timeLimit = (int )Configure::readOrFail ('Queue.workermaxruntime ' ) * 2 ;
436
445
if (Configure::read ('Queue.workertimeout ' ) !== null ) {
437
446
$ timeLimit = (int )Configure::read ('Queue.workertimeout ' );
438
447
}
@@ -450,6 +459,7 @@ protected function getConfig(array $args): array {
450
459
'groups ' => [],
451
460
'types ' => [],
452
461
'verbose ' => false ,
462
+ 'maxruntime ' => null ,
453
463
];
454
464
if (!empty ($ args ['verbose ' ])) {
455
465
$ config ['verbose ' ] = true ;
@@ -460,6 +470,9 @@ protected function getConfig(array $args): array {
460
470
if (!empty ($ args ['type ' ])) {
461
471
$ config ['types ' ] = $ this ->stringToArray ($ args ['type ' ]);
462
472
}
473
+ if (!empty ($ args ['max-runtime ' ])) {
474
+ $ config ['maxruntime ' ] = (int )$ args ['max-runtime ' ];
475
+ }
463
476
464
477
return $ config ;
465
478
}
0 commit comments