1 | <?php |
||
12 | abstract class AbstractBackoffStrategy implements BackoffStrategyInterface |
||
13 | { |
||
14 | /** @var AbstractBackoffStrategy Next strategy in the chain */ |
||
15 | protected $next; |
||
16 | |||
17 | /** @param AbstractBackoffStrategy $next Next strategy in the chain */ |
||
18 | public function setNext(AbstractBackoffStrategy $next) |
||
22 | |||
23 | /** |
||
24 | * Get the next backoff strategy in the chain |
||
25 | * |
||
26 | * @return AbstractBackoffStrategy|null |
||
27 | */ |
||
28 | public function getNext() |
||
32 | |||
33 | public function getBackoffPeriod( |
||
63 | |||
64 | /** |
||
65 | * Check if the strategy does filtering and makes decisions on whether or not to retry. |
||
66 | * |
||
67 | * Strategies that return false will never retry if all of the previous strategies in a chain defer on a backoff |
||
68 | * decision. |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | abstract public function makesDecision(); |
||
73 | |||
74 | /** |
||
75 | * Implement the concrete strategy |
||
76 | * |
||
77 | * @param int $retries Number of retries of the request |
||
78 | * @param RequestInterface $request Request that was sent |
||
79 | * @param Response $response Response that was received. Note that there may not be a response |
||
80 | * @param HttpException $e Exception that was encountered if any |
||
81 | * |
||
82 | * @return bool|int|null Returns false to not retry or the number of seconds to delay between retries. Return true |
||
83 | * or null to defer to the next strategy if available, and if not, return 0. |
||
84 | */ |
||
85 | abstract protected function getDelay( |
||
91 | } |
||
92 |