1 | <?php |
||
22 | final class RetryPlugin implements Plugin |
||
23 | { |
||
24 | /** |
||
25 | * Number of retry before sending an exception. |
||
26 | * |
||
27 | * @var int |
||
28 | */ |
||
29 | private $retry; |
||
30 | |||
31 | /** |
||
32 | * @var callable |
||
33 | */ |
||
34 | private $errorResponseDelay; |
||
35 | |||
36 | /** |
||
37 | * @var callable |
||
38 | */ |
||
39 | private $errorResponseDecider; |
||
40 | |||
41 | /** |
||
42 | * @var callable |
||
43 | */ |
||
44 | private $exceptionDecider; |
||
45 | |||
46 | /** |
||
47 | * @var callable |
||
48 | */ |
||
49 | private $exceptionDelay; |
||
50 | |||
51 | /** |
||
52 | * Store the retry counter for each request. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | private $retryStorage = []; |
||
57 | |||
58 | /** |
||
59 | * @param array $config { |
||
60 | * |
||
61 | * @var int $retries Number of retries to attempt if an exception occurs before letting the exception bubble up |
||
62 | * @var callable $error_response_decider A callback that gets a request and response to decide whether the request should be retried |
||
63 | * @var callable $exception_decider A callback that gets a request and an exception to decide after a failure whether the request should be retried |
||
64 | * @var callable $error_response_delay A callback that gets a request and response and the current number of retries and returns how many microseconds we should wait before trying again |
||
65 | * @var callable $exception_delay A callback that gets a request, an exception and the current number of retries and returns how many microseconds we should wait before trying again |
||
66 | * } |
||
67 | */ |
||
68 | 10 | public function __construct(array $config = []) |
|
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | 6 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise |
|
147 | |||
148 | /** |
||
149 | * @param int $retries The number of retries we made before. First time this get called it will be 0. |
||
150 | */ |
||
151 | 1 | public static function defaultErrorResponseDelay(RequestInterface $request, ResponseInterface $response, int $retries): int |
|
155 | |||
156 | /** |
||
157 | * @param int $retries The number of retries we made before. First time this get called it will be 0. |
||
158 | */ |
||
159 | 4 | public static function defaultExceptionDelay(RequestInterface $request, Exception $e, int $retries): int |
|
163 | |||
164 | /** |
||
165 | * @throws \Exception if retrying returns a failed promise |
||
166 | */ |
||
167 | 3 | private function retry(RequestInterface $request, callable $next, callable $first, string $chainIdentifier, int $delay): ResponseInterface |
|
177 | } |
||
178 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.