This repository was archived by the owner on May 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConsumerHeartbeatCommand.php
More file actions
56 lines (48 loc) · 1.81 KB
/
ConsumerHeartbeatCommand.php
File metadata and controls
56 lines (48 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Oro\Bundle\MessageQueueBundle\Command;
use Oro\Bundle\CronBundle\Command\CronCommandInterface;
use Oro\Bundle\CronBundle\Command\SynchronousCommandInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Cron command that checks that consumers are alive and pushes the message if there are no available consumers.
*/
class ConsumerHeartbeatCommand extends ContainerAwareCommand implements
CronCommandInterface,
SynchronousCommandInterface
{
const COMMAND_NAME = 'oro:cron:message-queue:consumer_heartbeat_check';
const HEARTBEAT_UPDATE_PERIOD_PARAMETER_NAME = 'oro_message_queue.consumer_heartbeat_update_period';
/** {@inheritdoc} */
public function getDefaultDefinition()
{
return sprintf(
'*/%s * * * *',
$this->getContainer()->getParameter(self::HEARTBEAT_UPDATE_PERIOD_PARAMETER_NAME)
);
}
/** {@inheritdoc} */
public function isActive()
{
return true;
}
/** {@inheritdoc} */
public function configure()
{
$this->setName(self::COMMAND_NAME)
->setDescription('Checks if there is alive consumers');
}
/** {@inheritdoc} */
protected function execute(InputInterface $input, OutputInterface $output)
{
// do nothing if check was disabled with 0 config option value
if ($this->getContainer()->getParameter(self::HEARTBEAT_UPDATE_PERIOD_PARAMETER_NAME) === 0) {
return;
}
$container = $this->getContainer();
if (!$container->get('oro_message_queue.consumption.consumer_heartbeat')->isAlive()) {
$container->get('oro_wamp.publisher')->send('oro/message_queue_heartbeat', []);
}
}
}