Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions src/Queue/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
*
Expand All @@ -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();
Expand All @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions tests/TestCase/Command/InfoCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down