Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
durationcountbased.php
1
<?php
8
namespace
Bitrix\Sender\Dispatch
;
9
10
use
Bitrix\Main\Localization\Loc
;
11
12
use
Bitrix\Sender\Message
;
13
use
Bitrix\Sender\Transport
;
14
15
Loc::loadMessages
(__FILE__);
16
21
class
DurationCountBased
22
{
24
private
$message;
25
27
private
$count;
28
36
public
static
function
create
(
Message
\
Adapter
$message)
37
{
38
return
new
static
($message);
39
}
40
46
public
function
__construct
(
Message
\
Adapter
$message)
47
{
48
$this->message = $message;
49
}
50
57
public
function
getInterval($count)
58
{
59
if
(!$count)
60
{
61
return
0;
62
}
63
64
$this->count = $count;
66
$limiter = current($this->
getLimiters
());
67
if
(!$limiter)
68
{
69
return
0;
70
}
71
72
$limit = $limiter->getLimit();
73
if
(!$limit)
74
{
75
return
0;
76
}
77
78
$timeouts = $this->
getLimitTimeouts
($limiter);
79
$unit = $this->
getLimitUnit
($limiter);
80
81
if
($timeouts)
82
{
83
$count = $this->count % ($limit * $timeouts);
84
}
85
else
86
{
87
$count = $this->count;
88
}
89
90
return
($timeouts * $unit) + ($count * $this->message->getSendDuration());
91
}
92
99
public
function
getIntervalDefault
($count)
100
{
101
$interval = $this->getInterval($count);
102
if
($interval)
103
{
104
return
$interval;
105
}
106
107
return
ceil(0.01 * $count);
108
}
109
110
protected
function
getLimitUnit
(Transport\
iLimiter
$limiter)
111
{
112
return
Transport\CountLimiter::getUnitInterval($limiter->getUnit());
113
}
114
115
protected
function
getLimitTimeouts
(Transport\
iLimiter
$limiter)
116
{
117
$count = $this->count;
118
$limit = $limiter->getLimit();
119
$count -= $limit - $limiter->getCurrent();
120
if
(!$count || !$limit)
121
{
122
return
0;
123
}
124
125
return
intval($count / $limit);
126
}
127
128
protected
function
getLimiters
()
129
{
130
$transport = $this->message->getTransport();
131
if
(!$transport)
132
{
133
return
array();
134
}
135
136
return
$transport->getLimiters($this->message);
137
}
138
}
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Sender\Dispatch\DurationCountBased
Definition
durationcountbased.php:22
Bitrix\Sender\Dispatch\DurationCountBased\create
static create(Message\Adapter $message)
Definition
durationcountbased.php:36
Bitrix\Sender\Dispatch\DurationCountBased\getLimitUnit
getLimitUnit(Transport\iLimiter $limiter)
Definition
durationcountbased.php:110
Bitrix\Sender\Dispatch\DurationCountBased\getLimiters
getLimiters()
Definition
durationcountbased.php:128
Bitrix\Sender\Dispatch\DurationCountBased\getIntervalDefault
getIntervalDefault($count)
Definition
durationcountbased.php:99
Bitrix\Sender\Dispatch\DurationCountBased\getLimitTimeouts
getLimitTimeouts(Transport\iLimiter $limiter)
Definition
durationcountbased.php:115
Bitrix\Sender\Dispatch\DurationCountBased\__construct
__construct(Message\Adapter $message)
Definition
durationcountbased.php:46
Bitrix\Sender\Entity\Message
Definition
message.php:27
Bitrix\Sender\Message\Adapter
Definition
adapter.php:21
Bitrix\Sender\Transport\iLimiter
Definition
ilimiter.php:16
Bitrix\Sender\Dispatch
Definition
duration.php:8
Bitrix\Sender\Message
Definition
adapter.php:9
Bitrix\Sender\Transport
Definition
adapter.php:9
modules
sender
lib
dispatch
durationcountbased.php
Создано системой
1.10.0