Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/main/java/me/itzg/helpers/curseforge/CurseForgeInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ public class CurseForgeInstaller {
public static final String REPO_SUBDIR_MODPACKS = "modpacks";
public static final String REPO_SUBDIR_MODS = "mods";
public static final String REPO_SUBDIR_WORLDS = "worlds";
private static final Duration BAD_FILE_DELAY = Duration.ofSeconds(5);
public static final int BAD_FILE_ATTEMPTS = 3;

private final Path outputDir;
private final Path resultsFile;
Expand Down Expand Up @@ -138,6 +136,12 @@ public class CurseForgeInstaller {
@Getter @Setter
int maxConcurrentDownloads;

@Getter @Setter
int fileDownloadRetries = 5;

@Getter @Setter
Duration fileDownloadRetryMinDelay = Duration.ofSeconds(5);

/**
*/
public void installFromModpackZip(Path modpackZip, String slug) {
Expand Down Expand Up @@ -776,18 +780,19 @@ private Mono<DownloadOrResolveResult> buildRetryableDownload(InstallContext con
)
// retry the deferred part above if one of the expected failure cases
.retryWhen(
Retry.backoff(BAD_FILE_ATTEMPTS, BAD_FILE_DELAY)
Retry.backoff(fileDownloadRetries, fileDownloadRetryMinDelay)
.filter(throwable ->
throwable instanceof FileHashInvalidException ||
throwable instanceof FailedRequestException ||
throwable instanceof IOException ||
throwable instanceof ChannelException
)
.doBeforeRetry(retrySignal ->
log.warn("Retry #{} download of {} @ {}:{} due to {}",
log.warn("Retry #{} download of {} @ {}:{} due to {}: {}",
retrySignal.totalRetries() + 1,
cfFile.getFileName(), modInfo.getName(), cfFile.getDisplayName(),
retrySignal.failure().getClass().getSimpleName()
retrySignal.failure().getClass().getSimpleName(),
retrySignal.failure().getMessage()
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -176,6 +177,16 @@ static class Listed {
)
int maxConcurrentDownloads;

@Option(names = "--file-download-retries", paramLabel = "COUNT",
description = "Default is ${DEFAULT-VALUE}"
)
int fileDownloadRetries = 5;

@Option(names = "--file-download-retry-min-delay", paramLabel = "DURATION",
description = "Default is ${DEFAULT-VALUE}"
)
Duration fileDownloadRetryMinDelay = Duration.ofSeconds(5);

@Override
public Integer call() throws Exception {
// https://www.curseforge.com/minecraft/modpacks/all-the-mods-8/files
Expand Down Expand Up @@ -214,7 +225,9 @@ public Integer call() throws Exception {
.setDisableApiCaching(disableApiCaching)
.setCacheArgs(cacheArgs)
.setForgeUrlArgs(forgeUrlArgs)
.setMaxConcurrentDownloads(maxConcurrentDownloads);
.setMaxConcurrentDownloads(maxConcurrentDownloads)
.setFileDownloadRetries(fileDownloadRetries)
.setFileDownloadRetryMinDelay(fileDownloadRetryMinDelay);

if (apiBaseUrl != null) {
installer.setApiBaseUrl(apiBaseUrl);
Expand Down