1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
MessageBox.php
См. документацию.
1
<?php
2
3
declare(strict_types=1);
4
5
namespace
Bitrix\Main\Messenger\Entity;
6
7
use Bitrix\Main\ArgumentException;
8
use Bitrix\Main\DI\ServiceLocator;
9
use Bitrix\Main\Messenger\Internals\Config\QueueConfigRegistry;
10
use Bitrix\Main\Type\DateTime;
11
15
final
class
MessageBox
16
{
17
private
?
int
$id =
null
;
18
19
private
string
$queueId;
20
21
private
int
|
string
|
null
$itemId =
null
;
22
23
private
string
$className;
24
25
private
DateTime
$createdAt;
26
27
private
DateTime
$availableAt;
28
29
private
int
$ttl = 3;
30
31
private
bool
$rejected =
false
;
32
33
public
function
__construct
(
private
readonly
MessageInterface
$message
)
34
{
35
$this->className = get_class($this->message);
36
$this->createdAt =
new
DateTime
();
37
$this->availableAt =
new
DateTime
();
38
}
39
40
public
function
getId
(): ?int
41
{
42
return
$this->id;
43
}
44
45
public
function
setId
(
int
$id): self
46
{
47
$this->
id
= $id;
48
49
return
$this;
50
}
51
52
public
function
getQueueId
(): string
53
{
54
return
$this->queueId;
55
}
56
57
public
function
setQueueId
(
string
$queueId): self
58
{
59
$this->queueId = $queueId;
60
61
return
$this;
62
}
63
64
public
function
getMessage
():
MessageInterface
65
{
66
return
$this->message
;
67
}
68
69
public
function
getCreatedAt
():
DateTime
70
{
71
return
$this->createdAt;
72
}
73
74
public
function
setCreatedAt
(
DateTime
$createdAt): self
75
{
76
$this->createdAt = $createdAt;
77
78
return
$this;
79
}
80
81
public
function
getItemId
(): int|string|null
82
{
83
return
$this->itemId;
84
}
85
86
public
function
setItemId
(
int
|
string
|
null
$itemId): self
87
{
88
$this->itemId = $itemId;
89
90
return
$this;
91
}
92
93
public
function
getClassName
(): string
94
{
95
return
$this->className;
96
}
97
98
public
function
getAvailableAt
():
DateTime
99
{
100
return
$this->availableAt;
101
}
102
103
public
function
setAvailableAt
(
DateTime
$availableAt): self
104
{
105
$this->availableAt = $availableAt;
106
107
return
$this;
108
}
109
110
public
function
getTtl
(): int
111
{
112
return
$this->ttl;
113
}
114
120
public
function
setTtl
(
int
$ttl): self
121
{
122
if
($ttl < 0)
123
{
124
throw
new
ArgumentException
(
'Ttl value should be a not negative number'
);
125
}
126
127
$this->ttl = $ttl;
128
129
return
$this;
130
}
131
132
public
function
isRejected
(): bool
133
{
134
return
$this->rejected;
135
}
136
137
public
function
isDied
(): bool
138
{
139
return
$this->ttl < 1;
140
}
141
142
public
function
reject
(): void
143
{
144
$this->rejected =
true
;
145
146
$this->ttl--;
147
148
if
($this->
isDied
())
149
{
150
return
;
151
}
152
153
if
($this->availableAt >
new
DateTime
())
154
{
155
return
;
156
}
157
158
$retryStrategy = ServiceLocator::getInstance()
159
->get(QueueConfigRegistry::class)
160
->getQueueConfig($this->queueId)
161
->retryStrategy
162
;
163
164
$retry = $retryStrategy->getMaxRetryCount() - $this->ttl;
165
166
$availableAt =
new
DateTime
();
167
168
$this->availableAt = $availableAt->add(
169
sprintf(
170
'+%s seconds'
,
171
intval($retryStrategy->getWaitingTime($retry) / 1000)
172
)
173
);
174
}
175
176
public
function
kill
(): self
177
{
178
$this->ttl = 0;
179
180
$this->rejected =
true
;
181
182
return
$this;
183
}
184
185
public
function
requeue
(?
int
$retryDelay): self
186
{
187
$this->ttl++;
188
189
if
($retryDelay > 0)
190
{
191
$availableAt =
new
DateTime
();
192
193
$this->availableAt = $availableAt->add(sprintf(
'+%s seconds'
, $retryDelay));
194
}
195
196
return
$this;
197
}
198
}
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Main\Messenger\Entity\MessageBox
Определения
MessageBox.php:16
Bitrix\Main\Messenger\Entity\MessageBox\getMessage
getMessage()
Определения
MessageBox.php:64
Bitrix\Main\Messenger\Entity\MessageBox\getCreatedAt
getCreatedAt()
Определения
MessageBox.php:69
Bitrix\Main\Messenger\Entity\MessageBox\getId
getId()
Определения
MessageBox.php:40
Bitrix\Main\Messenger\Entity\MessageBox\isRejected
isRejected()
Определения
MessageBox.php:132
Bitrix\Main\Messenger\Entity\MessageBox\setTtl
setTtl(int $ttl)
Определения
MessageBox.php:120
Bitrix\Main\Messenger\Entity\MessageBox\__construct
__construct(private readonly MessageInterface $message)
Определения
MessageBox.php:33
Bitrix\Main\Messenger\Entity\MessageBox\getItemId
getItemId()
Определения
MessageBox.php:81
Bitrix\Main\Messenger\Entity\MessageBox\getAvailableAt
getAvailableAt()
Определения
MessageBox.php:98
Bitrix\Main\Messenger\Entity\MessageBox\getQueueId
getQueueId()
Определения
MessageBox.php:52
Bitrix\Main\Messenger\Entity\MessageBox\setQueueId
setQueueId(string $queueId)
Определения
MessageBox.php:57
Bitrix\Main\Messenger\Entity\MessageBox\setItemId
setItemId(int|string|null $itemId)
Определения
MessageBox.php:86
Bitrix\Main\Messenger\Entity\MessageBox\kill
kill()
Определения
MessageBox.php:176
Bitrix\Main\Messenger\Entity\MessageBox\reject
reject()
Определения
MessageBox.php:142
Bitrix\Main\Messenger\Entity\MessageBox\setAvailableAt
setAvailableAt(DateTime $availableAt)
Определения
MessageBox.php:103
Bitrix\Main\Messenger\Entity\MessageBox\getClassName
getClassName()
Определения
MessageBox.php:93
Bitrix\Main\Messenger\Entity\MessageBox\getTtl
getTtl()
Определения
MessageBox.php:110
Bitrix\Main\Messenger\Entity\MessageBox\requeue
requeue(?int $retryDelay)
Определения
MessageBox.php:185
Bitrix\Main\Messenger\Entity\MessageBox\setCreatedAt
setCreatedAt(DateTime $createdAt)
Определения
MessageBox.php:74
Bitrix\Main\Messenger\Entity\MessageBox\isDied
isDied()
Определения
MessageBox.php:137
Bitrix\Main\Messenger\Entity\MessageBox\setId
setId(int $id)
Определения
MessageBox.php:45
Bitrix\Main\Type\DateTime
Определения
datetime.php:9
Bitrix\Main\Messenger\Entity\MessageInterface
Определения
MessageInterface.php:11
$message
$message
Определения
payment.php:8
bitrix
modules
main
lib
Messenger
Entity
MessageBox.php
Создано системой
1.14.0