Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
pushworker.php
1
<?php
2
3
namespace
Bitrix\Bizproc\Integration\Push
;
4
5
use
Bitrix\Main
;
6
use
Bitrix\Main\Engine\CurrentUser
;
7
use
Bitrix\Main\Loader
;
8
use
Bitrix\Pull
;
9
10
final
class
PushWorker
11
{
12
private
bool
$canUse;
13
private
static
$setJob =
false
;
14
private
static
$queue = [];
15
16
public
function
__construct
()
17
{
18
$this->canUse = Loader::includeModule(
'pull'
);
19
}
20
21
public
function
subscribe
(
int
$userId,
string
$command): void
22
{
23
if
($this->canUse)
24
{
25
\CPullWatch::Add($userId, $command);
26
}
27
}
28
29
public
function
send
(
string
$command, array $params, array $userIds = []): void
30
{
31
if
(empty($userIds))
32
{
33
$userIds = [CurrentUser::get()?->getId() ?? 0];
34
}
35
36
if
($this->canUse)
37
{
38
Pull\Event::add(
39
$userIds,
40
[
41
'module_id'
=>
'bizproc'
,
42
'command'
=> $command,
43
'params'
=> $params,
44
]
45
);
46
}
47
}
48
49
public
function
sendLast
(
string
$tag,
string
$command, array $params, array $userIds = [])
50
{
51
if
($this->canUse)
52
{
53
self::$queue[$tag] = [$command, $params, $userIds];
54
$this->setBackgroundJob();
55
}
56
}
57
58
private
function
setBackgroundJob()
59
{
60
if
(!self::$setJob)
61
{
62
Main\Application::getInstance()->addBackgroundJob(
63
[__CLASS__,
'doBackgroundJob'
],
64
[],
65
Main\
Application::JOB_PRIORITY_LOW
- 10
66
);
67
self::$setJob =
true
;
68
}
69
}
70
71
public
static
function
doBackgroundJob
()
72
{
73
$push =
new
self
();
74
75
foreach
(self::$queue as [$command, $params, $userIds])
76
{
77
$push->send($command, $params, $userIds);
78
}
79
}
80
}
Bitrix\Bizproc\Integration\Push\PushWorker
Definition
pushworker.php:11
Bitrix\Bizproc\Integration\Push\PushWorker\__construct
__construct()
Definition
pushworker.php:16
Bitrix\Bizproc\Integration\Push\PushWorker\sendLast
sendLast(string $tag, string $command, array $params, array $userIds=[])
Definition
pushworker.php:49
Bitrix\Bizproc\Integration\Push\PushWorker\subscribe
subscribe(int $userId, string $command)
Definition
pushworker.php:21
Bitrix\Bizproc\Integration\Push\PushWorker\send
send(string $command, array $params, array $userIds=[])
Definition
pushworker.php:29
Bitrix\Bizproc\Integration\Push\PushWorker\doBackgroundJob
static doBackgroundJob()
Definition
pushworker.php:71
Bitrix\Main\Application\JOB_PRIORITY_LOW
const JOB_PRIORITY_LOW
Definition
application.php:30
Bitrix\Main\Engine\CurrentUser
Definition
currentuser.php:8
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Bizproc\Integration\Push
Definition
basepush.php:3
Bitrix\Main
Bitrix\Pull
modules
bizproc
lib
integration
push
pushworker.php
Создано системой
1.10.0