|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\MessageQueue\Console; |
| 9 | + |
| 10 | +use Magento\Framework\Console\Cli; |
| 11 | +use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface; |
| 12 | +use Symfony\Component\Console\Command\Command; |
| 13 | +use Symfony\Component\Console\Input\InputInterface; |
| 14 | +use Symfony\Component\Console\Output\OutputInterface; |
| 15 | + |
| 16 | +/** |
| 17 | + * Command for put poison pill for MessageQueue consumers. |
| 18 | + */ |
| 19 | +class RestartConsumerCommand extends Command |
| 20 | +{ |
| 21 | + private const COMMAND_QUEUE_CONSUMERS_RESTART = 'queue:consumers:restart'; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var PoisonPillPutInterface |
| 25 | + */ |
| 26 | + private $poisonPillPut; |
| 27 | + |
| 28 | + /** |
| 29 | + * @param PoisonPillPutInterface $poisonPillPut |
| 30 | + * @param string|null $name |
| 31 | + */ |
| 32 | + public function __construct(PoisonPillPutInterface $poisonPillPut, $name = null) |
| 33 | + { |
| 34 | + parent::__construct($name); |
| 35 | + $this->poisonPillPut = $poisonPillPut; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @inheritdoc |
| 40 | + */ |
| 41 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 42 | + { |
| 43 | + $this->poisonPillPut->put(); |
| 44 | + return Cli::RETURN_SUCCESS; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @inheritdoc |
| 49 | + */ |
| 50 | + protected function configure() |
| 51 | + { |
| 52 | + $this->setName(self::COMMAND_QUEUE_CONSUMERS_RESTART); |
| 53 | + $this->setDescription('Restart MessageQueue consumers'); |
| 54 | + $this->setHelp( |
| 55 | + <<<HELP |
| 56 | +Command put poison pill for MessageQueue consumers and force to restart them after next status check. |
| 57 | +HELP |
| 58 | + ); |
| 59 | + parent::configure(); |
| 60 | + } |
| 61 | +} |
0 commit comments