1 | <?php |
||
20 | final class RetryMiddleware implements Middleware |
||
21 | { |
||
22 | public const DEFAULT_MAX_RETRIES = 3; |
||
23 | |||
24 | private $getDelay; |
||
25 | |||
26 | 4 | private function __construct(\Closure $getDelay) |
|
30 | |||
31 | public static function constant(int $maxRetries = self::DEFAULT_MAX_RETRIES, int $uInterval = 1000) : self |
||
37 | |||
38 | public static function exponential(int $maxRetries = self::DEFAULT_MAX_RETRIES, int $uBase = 1000) : self |
||
44 | |||
45 | public static function linear(int $maxRetries = self::DEFAULT_MAX_RETRIES, int $uStep = 1000) : self |
||
46 | { |
||
47 | return new self(static function (int $retries) use ($maxRetries, $uStep) { |
||
48 | return $retries > $maxRetries ? null : $uStep * $retries; |
||
49 | }); |
||
50 | } |
||
51 | |||
52 | 4 | public static function custom(\Closure $getDelay) : self |
|
58 | |||
59 | 4 | public function process(Request $request, Handler $handler) : Response |
|
76 | } |
||
77 |