Skip to content

Commit

Permalink
Remove jodah
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz committed Feb 8, 2024
1 parent d02ffe2 commit 7066c5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
5 changes: 0 additions & 5 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>net.jodah</groupId>
<artifactId>failsafe</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-exec</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.RetryPolicy;

@RequiredArgsConstructor
@Slf4j
Expand Down Expand Up @@ -128,17 +126,28 @@ private DistributionManifestV2 getDistributionManifest(ImageRef imageRef) {
}
}

private String downloadWithRetry(URL url, String accept, String auth) throws IOException {
RetryPolicy<Object> retryPolicy = new RetryPolicy<>()
.handle(Exception.class)
.withDelay(Duration.ofSeconds(Integer.parseInt(System.getProperty(CARNOTZET_MANIFEST_RETRY_DELAY_SECONDS, "1"))))
.withMaxRetries(Integer.parseInt(System.getProperty(CARNOTZET_MANIFEST_DOWNLOAD_RETRIES, "0")))
.onRetry((o) -> log.info("Download attempt failed: {} : Retrying... ", o.getLastFailure().toString()))
.onFailure((o) -> {
log.error("Download failed: {} ", o.getFailure().toString());
throw new IllegalStateException(o.getFailure());
});
return Failsafe.with(retryPolicy).get(() -> downloadWithoutRetry(url, accept, auth));
private String downloadWithRetry(URL url, String accept, String auth) {
int retryTimes = Integer.parseInt(System.getProperty(CARNOTZET_MANIFEST_DOWNLOAD_RETRIES, "0"));
int retryAfter = Integer.parseInt(System.getProperty(CARNOTZET_MANIFEST_RETRY_DELAY_SECONDS, "1"));

while(retryTimes > 0) {
try {
return downloadWithoutRetry(url, accept, auth);
} catch (Exception e) {
--retryTimes;
if (retryTimes > 0) {
log.info("Download attempt failed: {} : Retrying... ", e.getMessage());
try {
Thread.sleep(retryAfter);
} catch (InterruptedException e0) {}
} else {
log.error("Download failed: {} ", e);
throw e;
}
}
}

throw new RuntimeException("Download failed after " + retryTimes + " tries");
}

private String downloadWithoutRetry(URL url, String accept, String auth) {
Expand Down

0 comments on commit 7066c5b

Please sign in to comment.