Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
agentlistener.php
1<?php
2
4
6use Bitrix;
7use Bitrix\Calendar\Core\Queue;
8use CAgent;
9
11{
12 private const DEFAULT_DELAY = 60; // in seconds
13
14 private AgentEntity $agentEntity;
15
16 public function __construct(AgentEntity $agentEntity)
17 {
18 $this->agentEntity = $agentEntity;
19 }
20
24 public function handle()
25 {
26 if ($agentId = $this->getAgentId())
27 {
28 $time = new Bitrix\Main\Type\DateTime();
29
30 $delay = $this->agentEntity->getDelay() ?: self::DEFAULT_DELAY;
31 $time->add($delay . ' seconds');
32
33 CAgent::Update($agentId,[
34 'NEXT_EXEC' => $time,
35 ]);
36 }
37 }
38
42 private function getAgentId(): ?int
43 {
44 $agent = CAgent::getList(
45 [],
46 [
47 'MODULE_ID' => $this->agentEntity->getModule(),
48 '=NAME' => $this->agentEntity->getName(),
49 ]
50 )->Fetch();
51
52 if ($agent)
53 {
54 return $agent['ID'];
55 }
56
57 return null;
58 }
59}