|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * File: MigrationCommand.php |
| 7 | + * |
| 8 | + * @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl> |
| 9 | + * @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl) |
| 10 | + */ |
| 11 | + |
| 12 | +namespace LizardMedia\RabbitMqPlayground\Console\Command; |
| 13 | + |
| 14 | +use LizardMedia\RabbitMqPlayground\Model\Data\Entity; |
| 15 | +use Magento\Framework\Console\Cli; |
| 16 | +use Magento\Framework\MessageQueue\PublisherInterface; |
| 17 | +use Symfony\Component\Console\Command\Command; |
| 18 | +use Symfony\Component\Console\Input\InputInterface; |
| 19 | +use Symfony\Component\Console\Output\OutputInterface; |
| 20 | + |
| 21 | +/** |
| 22 | + * Class MigrationCommand |
| 23 | + * @package LizardMedia\ReviewsDataMigration\Console\Command |
| 24 | + * @codeCoverageIgnore |
| 25 | + */ |
| 26 | +class MassFeedCommand extends Command |
| 27 | +{ |
| 28 | + /** |
| 29 | + * @var string |
| 30 | + */ |
| 31 | + private const TOPIC_CREATE = 'entity.create'; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var string |
| 35 | + */ |
| 36 | + private const TOPIC_CONFIRM = 'entity.confirm'; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var string |
| 40 | + */ |
| 41 | + private const COMMAND_NAME = 'mass-feed'; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var string |
| 45 | + */ |
| 46 | + private const COMMAND_DESC = 'Feed'; |
| 47 | + |
| 48 | + /** |
| 49 | + * @var PublisherInterface |
| 50 | + */ |
| 51 | + private PublisherInterface $publisher; |
| 52 | + |
| 53 | + /** |
| 54 | + * FeedBufferCommand constructor. |
| 55 | + * @param PublisherInterface $publisher |
| 56 | + * @param string|null $name |
| 57 | + */ |
| 58 | + public function __construct(PublisherInterface $publisher, string $name = null) |
| 59 | + { |
| 60 | + parent::__construct($name); |
| 61 | + $this->publisher = $publisher; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @return void |
| 66 | + */ |
| 67 | + protected function configure(): void |
| 68 | + { |
| 69 | + parent::configure(); |
| 70 | + $this->setName(self::COMMAND_NAME) |
| 71 | + ->setDescription(self::COMMAND_DESC); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @param InputInterface $input |
| 76 | + * @param OutputInterface $output |
| 77 | + * @return int |
| 78 | + */ |
| 79 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 80 | + { |
| 81 | + for ($i = 0; $i <= 10000; $i++) { |
| 82 | + $entity = new Entity($i); |
| 83 | + $this->publisher->publish(self::TOPIC_CREATE, $entity); |
| 84 | + $this->publisher->publish(self::TOPIC_CONFIRM, $entity); |
| 85 | + } |
| 86 | + return Cli::RETURN_SUCCESS; |
| 87 | + } |
| 88 | +} |
0 commit comments