From 6ce782f71a38e2bf57edf8b86d45879aaeae00c7 Mon Sep 17 00:00:00 2001 From: Ollie Date: Fri, 2 Oct 2026 17:22:37 +0100 Subject: [PATCH 1/2] test: enforce that retry delay is after job timeouts --- tests/Jobs/JobTimeoutTest.php | 92 +++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/Jobs/JobTimeoutTest.php diff --git a/tests/Jobs/JobTimeoutTest.php b/tests/Jobs/JobTimeoutTest.php new file mode 100644 index 000000000..2dcc661da --- /dev/null +++ b/tests/Jobs/JobTimeoutTest.php @@ -0,0 +1,92 @@ +jobTimeouts(), + ...$this->horizonTimeouts(), + ...$this->queueWorkerTimeouts(), + ]; + + $this->assertIsInt($retryAfter); + $this->assertNotEmpty($timeouts); + + foreach ($timeouts as $source => $timeout) { + $this->assertIsInt($timeout, "{$source} must be an integer number of seconds."); + $this->assertGreaterThanOrEqual( + $timeout + 5, + $retryAfter, + "queue.connections.redis.retry_after must be at least 5 seconds longer than {$source} ({$timeout} seconds).", + ); + } + } + + private function jobTimeouts(): array { + $timeouts = []; + $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(app_path('Jobs'))); + + /** @var SplFileInfo $file */ + foreach ($files as $file) { + if (!$file->isFile() || $file->getExtension() !== 'php') { + continue; + } + + $relativePath = substr($file->getPathname(), strlen(app_path()) + 1, -4); + $class = 'App\\' . str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath); + + if (!class_exists($class) || !is_a($class, Job::class, true)) { + continue; + } + + $properties = (new ReflectionClass($class))->getDefaultProperties(); + + if (array_key_exists('timeout', $properties) && $properties['timeout'] !== null) { + $timeouts["{$class}::\$timeout"] = $properties['timeout']; + } + } + + return $timeouts; + } + + private function horizonTimeouts(): array { + return $this->findTimeouts(config('horizon'), 'horizon'); + } + + private function findTimeouts(array $config, string $path): array { + $timeouts = []; + + foreach ($config as $key => $value) { + $valuePath = "{$path}.{$key}"; + + if ($key === 'timeout') { + $timeouts[$valuePath] = $value; + } elseif (is_array($value)) { + $timeouts = array_merge($timeouts, $this->findTimeouts($value, $valuePath)); + } + } + + return $timeouts; + } + + private function queueWorkerTimeouts(): array { + $startScript = file_get_contents(base_path('start.sh')); + preg_match_all('/--timeout(?:=|\s+)(\d+)/', $startScript, $matches); + + $timeouts = []; + foreach ($matches[1] as $index => $timeout) { + $timeouts['start.sh --timeout #' . ($index + 1)] = intval($timeout); + } + + return $timeouts; + } +} From 58d46574c7b36738f5944c8277837cdeb1d2f4ae Mon Sep 17 00:00:00 2001 From: Ollie Date: Fri, 2 Oct 2026 22:29:32 +0100 Subject: [PATCH 2/2] fix: keep retry delay above job timeouts --- config/queue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/queue.php b/config/queue.php index 24be72ca5..9be0430aa 100644 --- a/config/queue.php +++ b/config/queue.php @@ -68,7 +68,7 @@ // seconds longer than every effective job or worker timeout to prevent jobs from being // re-attempted by another queue worker before it has finished executing or timed out. // https://laravel.com/framework/docs/11.x/queues#job-expirations-and-timeouts - 'retry_after' => 100, + 'retry_after' => 3605, 'block_for' => null, ], ],