Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
agentlistener.php
1
<?php
2
3
namespace
Bitrix\Calendar\Core\Queue\QueueListener
;
4
5
use
Bitrix\Calendar\Core\Queue\Agent\AgentEntity
;
6
use
Bitrix
;
7
use Bitrix\Calendar\Core\Queue;
8
use CAgent;
9
10
class
AgentListener
implements
Queue\Interfaces\Listener
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
}
Bitrix\Calendar\Core\Queue\Agent\AgentEntity
Definition
agententity.php:6
Bitrix\Calendar\Core\Queue\QueueListener\AgentListener
Definition
agentlistener.php:11
Bitrix\Calendar\Core\Queue\QueueListener\AgentListener\handle
handle()
Definition
agentlistener.php:24
Bitrix\Calendar\Core\Queue\QueueListener\AgentListener\__construct
__construct(AgentEntity $agentEntity)
Definition
agentlistener.php:16
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Calendar\Core\Queue\Interfaces\Listener
Definition
listener.php:6
Bitrix\Calendar\Core\Queue\QueueListener
Definition
agentlistener.php:3
Bitrix
modules
calendar
lib
core
queue
queuelistener
agentlistener.php
Создано системой
1.10.0