Skip to content

Commit 31de411

Browse files
committed
#23540: Queue consumers.
Add command to restart consumers.
1 parent 9378994 commit 31de411

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

app/code/Magento/MessageQueue/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<argument name="commands" xsi:type="array">
2121
<item name="startConsumerCommand" xsi:type="object">Magento\MessageQueue\Console\StartConsumerCommand\Proxy</item>
2222
<item name="consumerListCommand" xsi:type="object">Magento\MessageQueue\Console\ConsumerListCommand\Proxy</item>
23+
<item name="restartConsumerCommand" xsi:type="object">Magento\MessageQueue\Console\RestartConsumerCommand\Proxy</item>
2324
</argument>
2425
</arguments>
2526
</type>

0 commit comments

Comments
 (0)