Skip to content

Commit

Permalink
Merge pull request #11 from php-enqueue/consumption-do-not-print-swit…
Browse files Browse the repository at this point in the history
…ch-to-queue-if-queue-same

[consumption] Do not print "Switch to queue xxx" if queue the same.
  • Loading branch information
makasim authored Jan 9, 2017
2 parents 444b257 + d72bc2c commit 26df85b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/enqueue/Consumption/QueueConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,16 @@ public function consume(ExtensionInterface $runtimeExtension = null)
$logger = $context->getLogger() ?: new NullLogger();
$logger->info('Start consuming');

/** @var Queue|null $previousQueue */
$previousQueue = null;

while (true) {
try {
/** @var Queue $queue */
foreach ($this->boundProcessors as list($queue, $processor)) {
$logger->debug(sprintf('Switch to a queue %s', $queue->getQueueName()));
if (false == $previousQueue || $previousQueue->getQueueName() != $queue->getQueueName()) {
$logger->debug(sprintf('Switch to a queue %s', $queue->getQueueName()));
}

$messageConsumer = $messageConsumers[$queue->getQueueName()];

Expand All @@ -136,6 +141,8 @@ public function consume(ExtensionInterface $runtimeExtension = null)
$context->setPsrProcessor($processor);

$this->doConsume($extension, $context);

$previousQueue = $queue;
}
} catch (ConsumptionInterruptedException $e) {
$logger->info(sprintf('Consuming interrupted'));
Expand Down Expand Up @@ -215,7 +222,7 @@ protected function doConsume(ExtensionInterface $extension, Context $context)

$extension->onPostReceived($context);
} else {
$logger->info(sprintf('Idle'));
$logger->debug(sprintf('Idle'));

usleep($this->idleMicroseconds);
$extension->onIdle($context);
Expand Down

0 comments on commit 26df85b

Please sign in to comment.