@@ -134,7 +134,7 @@ public function run(array $args): int {
134134 $ startTime = time ();
135135
136136 while (!$ this ->exit ) {
137- $ this ->setPhpTimeout ();
137+ $ this ->setPhpTimeout ($ config [ ' maxruntime ' ] );
138138
139139 try {
140140 $ this ->updatePid ($ pid );
@@ -167,10 +167,11 @@ public function run(array $args): int {
167167 sleep (Config::sleeptime ());
168168 }
169169
170+ $ maxRuntime = $ config ['maxruntime ' ] ?: Configure::readOrFail ('Queue.workermaxruntime ' );
170171 // 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 ) {
172173 $ 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. ' );
174175 }
175176 if ($ this ->exit || mt_rand (0 , 100 ) > 100 - (int )Config::gcprob ()) {
176177 $ this ->io ->out ('Performing Old job cleanup. ' );
@@ -426,13 +427,21 @@ protected function stringToArray(string $param): array {
426427 }
427428
428429 /**
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.
430431 * If available, uses workertimeout config directly.
431432 *
433+ * @param int|null $maxruntime Max runtime in seconds if set via CLI option.
434+ *
432435 * @return void
433436 */
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 ;
436445 if (Configure::read ('Queue.workertimeout ' ) !== null ) {
437446 $ timeLimit = (int )Configure::read ('Queue.workertimeout ' );
438447 }
@@ -450,6 +459,7 @@ protected function getConfig(array $args): array {
450459 'groups ' => [],
451460 'types ' => [],
452461 'verbose ' => false ,
462+ 'maxruntime ' => null ,
453463 ];
454464 if (!empty ($ args ['verbose ' ])) {
455465 $ config ['verbose ' ] = true ;
@@ -460,6 +470,9 @@ protected function getConfig(array $args): array {
460470 if (!empty ($ args ['type ' ])) {
461471 $ config ['types ' ] = $ this ->stringToArray ($ args ['type ' ]);
462472 }
473+ if (!empty ($ args ['max-runtime ' ])) {
474+ $ config ['maxruntime ' ] = (int )$ args ['max-runtime ' ];
475+ }
463476
464477 return $ config ;
465478 }
0 commit comments