Skip to content

Commit

Permalink
Fix message from batch consumer command (#42)
Browse files Browse the repository at this point in the history
* Fixed message in BatchConsumerCommand and removed amount property
  • Loading branch information
andreea-anamaria authored Mar 1, 2021
1 parent 9988837 commit ed22633
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 deletions Command/BatchConsumerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ final class BatchConsumerCommand extends BaseRabbitMqCommand
*/
protected $consumer;

/** @var int */
protected $amount;

public function stopConsumer()
{
if ($this->consumer instanceof BatchConsumer) {
Expand Down Expand Up @@ -78,15 +75,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
define('AMQP_DEBUG', (bool) $input->getOption('debug'));
}

$this->amount = (int) $input->getOption('batches');
$batchAmountTarget = (int) $input->getOption('batches');

if (0 > $this->amount) {
throw new \InvalidArgumentException("The -b option should be null or greater than 0");
if (0 > $batchAmountTarget) {
throw new \InvalidArgumentException("The -b option should be greater than 0");
}

$this->initConsumer($input);

return $this->consumer->consume($this->amount);
return $this->consumer->consume($batchAmountTarget);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions RabbitMq/BatchConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BatchConsumer extends BaseAmqp implements DequeuerInterface
protected $gracefulMaxExecutionDateTime;

/** @var int */
private $target;
private $batchAmountTarget;

/**
* @param \DateTime|null $dateTime
Expand Down Expand Up @@ -106,9 +106,9 @@ public function setCallback($callback)
return $this;
}

public function consume(int $batchAmount = 0)
public function consume(int $batchAmountTarget = 0)
{
$this->target = $batchAmount;
$this->batchAmountTarget = $batchAmountTarget;

$this->setupConsumer();

Expand Down Expand Up @@ -372,7 +372,7 @@ protected function maybeStopConsumer()
pcntl_signal_dispatch();
}

if ($this->forceStop || ($this->batchAmount == $this->target && $this->target > 0)) {
if ($this->forceStop || ($this->batchAmount == $this->batchAmountTarget && $this->batchAmountTarget > 0)) {
$this->stopConsuming();
}

Expand Down

0 comments on commit ed22633

Please sign in to comment.