retry4j
retry4j copied to clipboard
Get last exception
Could you please add a way to get the last exception from a BackoffStrategy.
@jflefebvre06 - You can already check the last exception that generated a retry by looking in the Status
object - look in the documentation here and let me know if this already covers what you are asking for: https://github.com/elennick/retry4j#call-status
No, Status is not accessible from BackoffStrategy
public interface BackoffStrategy {
Duration getDurationToWait(int numberOfTriesFailed, Duration delayBetweenAttempts);
default void validateConfig(RetryConfig config) {}
}
Could you share an example of what you're trying to get access to? Do you have your own custom BackoffStrategy
implementation that contains logic that can throw an exception?
The use case is to manage http too many requests
Duration getDurationToWait(int numberOfTriesFailed, Duration delayBetweenAttempts) {
if(exception.getHttpStatus()==429)
return Duration.ofMinutes(1);
else
return Duration.ofSeconds(2);
}
@jflefebvre06 ok I understand... you want to be able to have more granular retry control over a single callable. Retry4j does not support this type of case at the moment. I'm not sure that implementing it inside a backoff strategy would be the correct approach... a better design would probably be to allow multiple retry configurations for a single callable, so that different configs could handle different exception types or return values. Please feel free to take a shot at an implementation and open a PR if you would like. Let me know if you want to discuss the design further before you do so. Thanks!