diff --git a/src/Queue/Processor.php b/src/Queue/Processor.php index 80ee30a2..dacf6b1c 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,30 @@ 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 { + try { + $this->captureOutput = $this->QueuedJobs->getSchema()->hasColumn('output'); + } catch (Throwable) { + $this->captureOutput = false; + } + } + } + + return $this->captureOutput; + } + /** * Signal handling to queue worker for clean shutdown * @@ -372,7 +401,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 +424,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(); 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