1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
MultiplierRetryStrategy.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
7use Exception;
8
10{
18 public function __construct(
19 private readonly int $maxRetries = 3,
20 private readonly int $delayMilliseconds = 100,
21 private readonly float $multiplier = 2,
22 private readonly int $maxDelayMilliseconds = 0,
23 private readonly float $jitter = 0.1
24 )
25 {
26 }
27
28 public function getMaxRetryCount(): int
29 {
30 return $this->maxRetries;
31 }
32
40 public function getWaitingTime(int $retry = 1): int
41 {
42 $delay = $this->delayMilliseconds * $this->multiplier ** $retry;
43
44 if ($this->jitter > 0 && $this->jitter < 1)
45 {
46 $randomness = (int)min(\PHP_INT_MAX, $delay * $this->jitter);
47
48 $delay += random_int(-$randomness, +$randomness);
49 }
50
51 if ($delay > $this->maxDelayMilliseconds && $this->maxDelayMilliseconds !== 0)
52 {
53 return $this->maxDelayMilliseconds;
54 }
55
56 return (int)min(\PHP_INT_MAX, ceil($delay));
57 }
58}
__construct(private readonly int $maxRetries=3, private readonly int $delayMilliseconds=100, private readonly float $multiplier=2, private readonly int $maxDelayMilliseconds=0, private readonly float $jitter=0.1)
Определения MultiplierRetryStrategy.php:18