fix: sleep in MdsTaskRetryWrapper
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/push/docs Pipeline was successful

This commit is contained in:
Johannes Frohnmeyer 2024-07-10 09:41:09 +02:00
parent 84b1120efb
commit d2c1efe63a
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 10 additions and 1 deletions

View File

@ -12,7 +12,7 @@ public record MdsTaskRetryWrapper(Map<String, ExponentialBackoff> backoffs, Thro
public void accept(MdsMod mod) throws IOException { public void accept(MdsMod mod) throws IOException {
String key = mod.getMetadataPath().getFileName().toString() + "/" + inner.getClass().getTypeName(); String key = mod.getMetadataPath().getFileName().toString() + "/" + inner.getClass().getTypeName();
ExponentialBackoff backoff = backoffs.computeIfAbsent(key, _ -> new ExponentialBackoff()); ExponentialBackoff backoff = backoffs.computeIfAbsent(key, _ -> new ExponentialBackoff());
if (!backoff.shouldTry()) return; backoff.sleep();
try { try {
inner.accept(mod); inner.accept(mod);
backoff.success(); backoff.success();

View File

@ -12,6 +12,15 @@ public class ExponentialBackoff {
return retries == 0 || System.currentTimeMillis() > nextRetry; return retries == 0 || System.currentTimeMillis() > nextRetry;
} }
public void sleep() {
try {
long time = nextRetry - System.currentTimeMillis();
if (time > 0) Thread.sleep(time);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
public void success() { public void success() {
retries = 0; retries = 0;
} }