Skip to content

Commit fc591cf

Browse files
committed
Allow 0 again.
1 parent 3115869 commit fc591cf

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

config/app.example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
return [
1111
'Queue' => [
12-
// seconds of running time after which the worker process will terminate (0 = unlimited)
12+
// seconds of running time after which the worker process will terminate (0 = unlimited, but not recommended)
1313
'workerLifetime' => 60, // 1 minutes
1414
// Legacy: 'workermaxruntime' is deprecated but still supported
1515

docs/sections/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ You may create a file called `app_queue.php` inside your `config` folder (NOT th
3939
// Legacy: 'workermaxruntime' is deprecated but still supported
4040
```
4141

42-
**Important:** This value cannot be 0. A value of 0 would mean "unlimited" which is not supported and will throw a RuntimeException. This setting is required to prevent workers from running indefinitely and potentially piling up if spawned faster than they can terminate, which could overload your server.
42+
**Important:** While 0 (unlimited) is technically allowed, it is **strongly discouraged**. Using 0 means workers will run indefinitely, which can lead to workers piling up if spawned faster than they can naturally terminate (e.g., when there are no jobs), potentially overloading your server.
4343

4444
If you need workers to run for extended periods, use a very large value (e.g., 86400 for 24 hours). However, it's recommended to use shorter durations (e.g., 60-300 seconds) with cronjob respawning for better control and safety.
4545

src/Queue/Config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public static function defaultworkertimeout(): int {
3737
}
3838

3939
/**
40-
* Seconds of running time after which the worker will terminate (0 = unlimited)
40+
* Seconds of running time after which the worker will terminate.
41+
* Note: 0 = unlimited is allowed but not recommended. Use a non-zero value for better control.
4142
*
4243
* @return int
4344
*/

src/Queue/Processor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ public function run(array $args): int {
175175
}
176176

177177
$workerLifetime = Configure::read('Queue.workerLifetime') ?? Configure::read('Queue.workermaxruntime');
178-
if (!$workerLifetime) {
178+
if ($workerLifetime === null) {
179179
throw new RuntimeException('Queue.workerLifetime (or deprecated workermaxruntime) config is required');
180180
}
181-
$maxRuntime = $config['maxruntime'] ?: $workerLifetime;
181+
$maxRuntime = $config['maxruntime'] ?: (int)$workerLifetime;
182182
// check if we are over the maximum runtime and end processing if so.
183-
if ((time() - $startTime) >= $maxRuntime) {
183+
if ($maxRuntime > 0 && (time() - $startTime) >= $maxRuntime) {
184184
$this->exit = true;
185185
$this->io->out('Reached runtime of ' . (time() - $startTime) . ' Seconds (Max ' . $maxRuntime . '), terminating.');
186186
}

0 commit comments

Comments
 (0)