in validator/src/main/java/com/amazon/aoc/helpers/RetryHelper.java [34:59]
public static boolean retry(
int retryCount, int sleepInMilliSeconds, boolean throwExceptionInTheEnd, Retryable retryable)
throws Exception {
Exception exceptionInTheEnd = null;
int initialCount = retryCount;
while (retryCount-- > 0) {
try {
log.info("retry attempt left : {} ", retryCount);
retryable.execute();
return true;
} catch (Exception ex) {
exceptionInTheEnd = ex;
if (retryCount != 0) { // don't sleep before leave this loop
log.info("retrying after {} seconds",
TimeUnit.MILLISECONDS.toSeconds(sleepInMilliSeconds));
TimeUnit.MILLISECONDS.sleep(sleepInMilliSeconds);
}
}
}
log.error("All {} retries exhausted", initialCount);
if (throwExceptionInTheEnd) {
throw exceptionInTheEnd;
}
return false;
}