From b17a046c6f42fa36227eed79582a5235e0099360 Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 29 Jan 2026 18:43:12 +0100 Subject: [PATCH 1/2] Auto-detect captureOutput based on output column existence Instead of requiring explicit `Queue.captureOutput` configuration, the Processor now auto-detects whether to capture output by checking if the `output` column exists on the `queued_jobs` table. Explicit config still takes precedence. The result is cached per worker lifetime so the schema check only happens once. --- src/Queue/Processor.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Queue/Processor.php b/src/Queue/Processor.php index 80ee30a2..64739295 100644 --- a/src/Queue/Processor.php +++ b/src/Queue/Processor.php @@ -86,6 +86,11 @@ class Processor { */ protected ?QueuedJob $currentJob = null; + /** + * @var bool|null + */ + protected ?bool $captureOutput = null; + /** * @param \Queue\Console\Io $io * @param \Psr\Log\LoggerInterface $logger @@ -225,7 +230,7 @@ protected function runJob(QueuedJob $queuedJob, string $pid): void { ]); EventManager::instance()->dispatch($event); - $captureOutput = (bool)Configure::read('Queue.captureOutput'); + $captureOutput = $this->captureOutput(); if ($captureOutput) { $maxOutputSize = (int)(Configure::read('Queue.maxOutputSize') ?: 65536); $this->io->enableOutputCapture($maxOutputSize); @@ -361,6 +366,26 @@ protected function getTaskConf(): array { return $this->taskConf; } + /** + * Whether to capture task output into the DB. + * + * Auto-detects based on `output` column existence if not explicitly configured. + * + * @return bool + */ + protected function captureOutput(): bool { + if ($this->captureOutput === null) { + $configured = Configure::read('Queue.captureOutput'); + if ($configured !== null) { + $this->captureOutput = (bool)$configured; + } else { + $this->captureOutput = $this->QueuedJobs->getSchema()->hasColumn('output'); + } + } + + return $this->captureOutput; + } + /** * Signal handling to queue worker for clean shutdown * @@ -372,7 +397,7 @@ protected function exit(int $signal): void { if ($this->currentJob) { $failureMessage = 'Worker process terminated by signal (SIGTERM) - job execution interrupted due to timeout or manual termination'; $capturedOutput = null; - if ((bool)Configure::read('Queue.captureOutput')) { + if ($this->captureOutput()) { $maxOutputSize = (int)(Configure::read('Queue.maxOutputSize') ?: 65536); $capturedOutput = $this->io->getOutputAsText($maxOutputSize); $this->io->disableOutputCapture(); @@ -395,7 +420,7 @@ protected function abort(int $signal = 1): void { if ($this->currentJob) { $failureMessage = 'Worker process aborted by signal (' . $signal . ') - job execution interrupted'; $capturedOutput = null; - if ((bool)Configure::read('Queue.captureOutput')) { + if ($this->captureOutput()) { $maxOutputSize = (int)(Configure::read('Queue.maxOutputSize') ?: 65536); $capturedOutput = $this->io->getOutputAsText($maxOutputSize); $this->io->disableOutputCapture(); From 60bc2234bc49da4aef759bfd14733195b3a81570 Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 29 Jan 2026 18:52:00 +0100 Subject: [PATCH 2/2] Fix CI: handle mock table schema in captureOutput() and suppress deprecation in test Wrap getSchema()->hasColumn() in try/catch to handle mock tables in tests (and any edge case in production). Suppress E_USER_DEPRECATED in InfoCommandTest that deliberately uses old config keys. --- src/Queue/Processor.php | 6 +++++- tests/TestCase/Command/InfoCommandTest.php | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Queue/Processor.php b/src/Queue/Processor.php index 64739295..dacf6b1c 100644 --- a/src/Queue/Processor.php +++ b/src/Queue/Processor.php @@ -379,7 +379,11 @@ protected function captureOutput(): bool { if ($configured !== null) { $this->captureOutput = (bool)$configured; } else { - $this->captureOutput = $this->QueuedJobs->getSchema()->hasColumn('output'); + try { + $this->captureOutput = $this->QueuedJobs->getSchema()->hasColumn('output'); + } catch (Throwable) { + $this->captureOutput = false; + } } } diff --git a/tests/TestCase/Command/InfoCommandTest.php b/tests/TestCase/Command/InfoCommandTest.php index a34ec708..a2d7424a 100644 --- a/tests/TestCase/Command/InfoCommandTest.php +++ b/tests/TestCase/Command/InfoCommandTest.php @@ -54,8 +54,14 @@ public function testExecuteWithNewConfigNames(): void { Configure::write('Queue.defaultworkerretries', 2); Configure::write('Queue.workertimeout', 120); + // Suppress deprecation warnings triggered by Config methods reading old keys + $errorLevel = error_reporting(); + error_reporting($errorLevel & ~E_USER_DEPRECATED); + $this->exec('queue info'); + error_reporting($errorLevel); + $output = $this->_out->output(); // Check that new config names are displayed with old names noted