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
10 changes: 7 additions & 3 deletions src/Queue/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ public function run(array $args): int {

if ($config['verbose']) {
$this->log('run', $pid, false);
$this->io->out('[' . date('Y-m-d H:i:s') . '] Looking for Job ...');
}
$this->io->out('[' . date('Y-m-d H:i:s') . '] Looking for Job ...');

$queuedJob = $this->QueuedJobs->requestJob($this->getTaskConf(), $config['groups'], $config['types']);

Expand All @@ -239,7 +239,9 @@ public function run(array $args): int {
$this->io->out('nothing to do, exiting.');
$this->exit = true;
} else {
$this->io->out('nothing to do, sleeping.');
if ($config['verbose']) {
$this->io->out('nothing to do, sleeping.');
}
sleep(Config::sleeptime());
}

Expand All @@ -256,7 +258,9 @@ public function run(array $args): int {
// shutdown sweep is redundant. `cleanOldJobs()` stays —
// that's about the queued_jobs table, not workers.
}
$this->io->hr();
if ($config['verbose']) {
$this->io->hr();
}
}

$this->deletePid($pid);
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase/Command/RunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function testExecute(): void {
$this->exec('queue run');

$output = $this->_out->output();
$this->assertStringContainsString('Looking for Job', $output);
// Worker loop ran to completion. The per-iteration heartbeat is
// verbose-only now, so assert on the always-on termination event.
$this->assertStringContainsString('terminating.', $output);
$this->assertExitCode(0);
}

Expand All @@ -63,7 +65,7 @@ public function testServiceInjection(): void {
$this->exec('queue run');

$output = $this->_out->output();
$this->assertStringContainsString('Looking for Job', $output);
$this->assertStringContainsString('Running Job of type "Foo"', $output);
$this->assertStringContainsString('CakePHP Foo Example.', $output);
$this->assertStringContainsString('My TestService', $output);
$this->assertExitCode(0);
Expand Down
46 changes: 46 additions & 0 deletions tests/TestCase/Queue/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,52 @@ public function testRun() {
$this->assertSame(CommandInterface::CODE_SUCCESS, $result);
}

/**
* Without verbose, the idle-poll heartbeat ("Looking for Job ...",
* "nothing to do, sleeping.", and the trailing horizontal rule) must
* stay silent so a quiet queue doesn't spam stdout/log files.
*
* @return void
*/
public function testRunNonVerboseSuppressesIdlePollOutput() {
Configure::write('Queue.exitwhennothingtodo', true);

$out = new ConsoleOutput();
$err = new ConsoleOutput();
$this->Processor = new Processor(new Io(new ConsoleIo($out, $err)), new NullLogger());

$result = $this->Processor->run([]);

$this->assertSame(CommandInterface::CODE_SUCCESS, $result);
$output = $out->output();
$this->assertStringNotContainsString('Looking for Job', $output);
$this->assertStringNotContainsString('nothing to do, sleeping', $output);
$this->assertStringNotContainsString("\n---", $output);
// One-shot exit event still fires: that's not steady-state noise.
$this->assertStringContainsString('nothing to do, exiting.', $output);
}

/**
* Verbose mode keeps the existing per-iteration heartbeat so operators
* who opt in still see liveness output.
*
* @return void
*/
public function testRunVerboseShowsIdlePollOutput() {
Configure::write('Queue.exitwhennothingtodo', true);

$out = new ConsoleOutput();
$err = new ConsoleOutput();
$this->Processor = new Processor(new Io(new ConsoleIo($out, $err)), new NullLogger());

$result = $this->Processor->run(['verbose' => true]);

$this->assertSame(CommandInterface::CODE_SUCCESS, $result);
$output = $out->output();
$this->assertStringContainsString('Looking for Job', $output);
$this->assertStringContainsString('nothing to do, exiting.', $output);
}

/**
* Helper method for skipping tests that need a real connection.
*
Expand Down
Loading