Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
examplerule.php
1<?php
2
4
5use Bitrix;
11use Bitrix\Calendar\Core\Queue\Rule\WakeUpAgentTrait;
12
13class ExampleRule extends DbRule
14{
15 use WakeUpAgentTrait;
16
22 protected function getTargetQueue(Interfaces\Message $message): ?Queue
23 {
24 $routingKey = $message->getHeaders()[Dictionary::HEADER_KEYS['routingKey']] ?? null;
25 if ($routingKey === 'example.test')
26 {
27 $queue = (new QueueFactory())->getById(QueueRegistry::QUEUE_LIST['EventDelayedSync']);
28 return $queue;
29 }
30
31 return null;
32 }
33
39 protected function getMessageHash(Interfaces\Message $message): string
40 {
41 return 'ExamplePrefix_' . $message->getBody()['exampleField'];
42 }
43
44 protected function handleRuleMasterFinish(Bitrix\Main\Event $event): Bitrix\Main\EventResult
45 {
46 $result = $this->wakeupAgent('Name of agent');
47 if ($result->isSuccess())
48 {
49 $result = new Bitrix\Main\EventResult(Bitrix\Main\EventResult::SUCCESS, []);
50 }
51 else
52 {
53 $result = new Bitrix\Main\EventResult(Bitrix\Main\EventResult::ERROR, []);
54 }
55
56 return $result;
57 }
58}