diff --git a/src/Command/SendEventsCommand.php b/src/Command/SendEventsCommand.php index 9428f70..0e2dfeb 100644 --- a/src/Command/SendEventsCommand.php +++ b/src/Command/SendEventsCommand.php @@ -11,6 +11,7 @@ use Setono\SyliusFacebookPlugin\Workflow\SendPixelEventWorkflow; use Symfony\Component\Console\Command\LockableTrait; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\WorkflowInterface; @@ -47,6 +48,28 @@ public function __construct( parent::__construct($defaultDelay); } + protected function configure(): void + { + parent::configure(); + + $this + ->addOption( + 'loops', + 'l', + InputOption::VALUE_REQUIRED, + 'Loops to handle before exit. Default (0) value will handle all records before exit', + 0 + ) + ->addOption( + 'chunk', + 'c', + InputOption::VALUE_REQUIRED, + 'Limit of records to handle in one loop', + 1000 + ) + ; + } + protected function execute(InputInterface $input, OutputInterface $output): int { if (!$this->lock()) { @@ -58,13 +81,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int $delay = $input->getOption('delay'); Assert::integerish($delay); - while ($this->pixelEventRepository->hasConsentedPending((int) $delay)) { + $loops = $input->getOption('loops'); + Assert::integerish($loops); + + $chunk = $input->getOption('chunk'); + Assert::integerish($chunk); + + $loop = 1; + while ((0 === $loops || $loop <= $loops) && $this->pixelEventRepository->hasConsentedPending((int) $delay)) { $bulkIdentifier = uniqid('bulk-', true); - $this->pixelEventRepository->assignBulkIdentifierToPendingConsented($bulkIdentifier, (int) $delay); + $this->pixelEventRepository->assignBulkIdentifierToPendingConsented($bulkIdentifier, (int) $delay, (int) $chunk); $pixelEvents = $this->pixelEventRepository->findByBulkIdentifier($bulkIdentifier); $output->writeln(sprintf( - 'Found %s events to send.', + '%s. Found %s events to send.', + $loop, count($pixelEvents) ), OutputInterface::VERBOSITY_VERBOSE); @@ -102,6 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $this->entityManager->clear(); + ++$loop; } return 0;