1212 *
1313 * @author Tobias Schultze <http://tobion.de>
1414 */
15- class RetryConfigurator
15+ final class RetryConfigurator
1616{
1717 /**
1818 * @var string[]
@@ -27,20 +27,18 @@ class RetryConfigurator
2727 /**
2828 * @var int
2929 */
30- private $ delayInMs ;
30+ private $ delayInMs = 0 ;
3131
3232 /**
3333 * Configures the retry logic. By default:
3434 *
3535 * - The callable is retried twice (i.e. max three executions). If it still fails, the last error is rethrown.
36- * - Retries have a 300 milliseconds delay between them.
37- * - Every \Throwable will trigger the retry logic, i.e. both exceptions and errors .
36+ * - Retries have a no delay between them.
37+ * - Every \Throwable will trigger the retry logic, i.e. both \Exception and \Error .
3838 */
39- public function __construct (int $ maxRetries = 2 , int $ delayInMs = 300 , string $ exceptionToRetry = \Throwable::class )
39+ public function __construct (int $ maxRetries = 2 )
4040 {
4141 $ this ->maxRetries = $ maxRetries ;
42- $ this ->delayInMs = $ delayInMs ;
43- $ this ->setRetryableExceptions ($ exceptionToRetry );
4442 }
4543
4644 /**
@@ -53,7 +51,7 @@ public function __construct(int $maxRetries = 2, int $delayInMs = 300, string $e
5351 *
5452 * @return $this
5553 */
56- public function setRetryableExceptions (string $ exceptionClass , string ...$ moreExceptionClasses ): self
54+ public function retryOnSpecificExceptions (string $ exceptionClass , string ...$ moreExceptionClasses ): self
5755 {
5856 array_unshift ($ moreExceptionClasses , $ exceptionClass );
5957 $ this ->retryableExceptionClasses = $ moreExceptionClasses ;
@@ -66,7 +64,7 @@ public function setRetryableExceptions(string $exceptionClass, string ...$moreEx
6664 *
6765 * @return $this
6866 */
69- public function setMaxRetries (int $ maxRetries ): self
67+ public function maxRetries (int $ maxRetries ): self
7068 {
7169 $ this ->maxRetries = $ maxRetries ;
7270
@@ -80,41 +78,13 @@ public function setMaxRetries(int $maxRetries): self
8078 *
8179 * @return $this
8280 */
83- public function setDelayInMs (int $ milliseconds ): self
81+ public function delayInMs (int $ milliseconds ): self
8482 {
8583 $ this ->delayInMs = $ milliseconds ;
8684
8785 return $ this ;
8886 }
8987
90- /**
91- * Returns the exception classes/interfaces to catch and retry on.
92- *
93- * If empty, every exception will trigger the retry logic.
94- *
95- * @return string[]
96- */
97- public function getRetryableExceptions (): array
98- {
99- return $ this ->retryableExceptionClasses ;
100- }
101-
102- /**
103- * Returns the maximum number of retries.
104- */
105- public function getMaxRetries (): int
106- {
107- return $ this ->maxRetries ;
108- }
109-
110- /**
111- * Returns the delay between retries in milliseconds.
112- */
113- public function getDelayInMs (): int
114- {
115- return $ this ->delayInMs ;
116- }
117-
11888 /**
11989 * Returns a callable that decorates the given operation that should be retried on failure.
12090 */
@@ -123,7 +93,7 @@ public function decorate(callable $operation): RetryingCallable
12393 $ handlers = [];
12494
12595 // we can skip the handler in this default case
126- if ([\Throwable::class] !== $ this ->retryableExceptionClasses ) {
96+ if ([] !== $ this -> retryableExceptionClasses && [ \Throwable::class] !== $ this ->retryableExceptionClasses ) {
12797 $ handlers [] = new RethrowNonRetryableExceptions (...$ this ->retryableExceptionClasses );
12898 }
12999
0 commit comments