fix: sleep in MdsTaskRetryWrapper
This commit is contained in:
parent
84b1120efb
commit
d2c1efe63a
@ -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();
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user