Add retry with condition support?
- Dominant language
- Scala
- Stars
- 1.6k
- Forks
- 211
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 89
Description
Motivation:
Currently, the retry in Patterns only retry for an exception ocurr, but there are cases the result itself is a failure but the async Future is `Success`. eg `Future>` and the `XXXResult` has a method `isSuccsss` and `errorCode` and we want to retry for some errorCode.
How about add a` Predicate shouldRetryPredicate` to the parameter list? I have something like this in my code base at work.
```
public static V retryWithBackoff(
final Callable callable,
final Predicate shouldRetryPredicate,
final int maxRetryTime,
final int sleepInMills,
final String hint) {
....
}
```
And in resilience4j-retry it's named `retryOnResult`:
```java
RetryConfig config = RetryConfig.custom()
.maxAttempts(2)
.waitDuration(Duration.ofMillis(1000))
.retryOnResult(response -> response.getStatus() == 500)
.retryOnException(e -> e instanceof WebServiceException)
.retryExceptions(IOException.class, TimeoutException.class)
.ignoreExceptions(BusinessException.class, OtherBusinessException.class)
.failAfterMaxAttempts(true)
.build();
```
Contributor guide
Assessment
This issue has not been assessed yet.