Skip to content

Commit e447805

Browse files
committed
Auto-cap task timeout to defaultRequeueTimeout.
Instead of warning when a task timeout exceeds the requeue timeout, automatically cap it to prevent duplicate execution.
1 parent 18ac987 commit e447805

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

docs/sections/configuration.md

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

26-
**Important:** Individual task `timeout` property values should NOT exceed this `defaultRequeueTimeout` value. If a task has a timeout longer than the global requeue timeout, the job will be requeued before the task completes, causing duplicate execution. Always ensure `defaultRequeueTimeout` is greater than your longest task timeout (recommended: at least 2x the longest task timeout).
26+
**Note:** Individual task `timeout` values are automatically capped to this `defaultRequeueTimeout` value to prevent duplicate execution. If a task needs a longer timeout, increase `defaultRequeueTimeout` accordingly (recommended: at least 2x your longest task timeout).
2727

2828
- Default number of retries if a job fails or times out:
2929

docs/sections/custom_tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class YourNameForItTask extends Task {
2727

2828
/**
2929
* Timeout in seconds for this specific task.
30-
* Should NOT exceed defaultRequeueTimeout to prevent the job being requeued while still running.
30+
* Automatically capped to defaultRequeueTimeout if higher.
3131
*
3232
* @var ?int
3333
*/

src/Queue/Config.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,9 @@ public static function taskConfig(array $tasks): array {
142142

143143
$taskTimeout = $taskConfig['timeout'] ?? $taskObject->timeout ?? $defaultTimeout;
144144

145-
// Warn if task timeout is greater than the requeue timeout, which can cause premature requeuing
145+
// Auto-cap task timeout to defaultRequeueTimeout to prevent duplicate execution
146146
if ($taskTimeout > $defaultTimeout) {
147-
trigger_error(
148-
sprintf(
149-
'Task "%s" has timeout (%d seconds) larger than defaultRequeueTimeout (%d seconds). '
150-
. 'The job will be requeued after %d seconds even though the task expects to run for %d seconds. '
151-
. 'This can cause duplicate execution. Consider increasing defaultRequeueTimeout or decreasing the task timeout.',
152-
$task,
153-
$taskTimeout,
154-
$defaultTimeout,
155-
$defaultTimeout,
156-
$taskTimeout,
157-
),
158-
E_USER_WARNING,
159-
);
147+
$taskTimeout = $defaultTimeout;
160148
}
161149

162150
$config[$task]['class'] = $className;

0 commit comments

Comments
 (0)