Skip to content

Commit 43204cd

Browse files
authored
cf: default file download retries is 5 and now configurable (#628)
1 parent e865675 commit 43204cd

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/main/java/me/itzg/helpers/curseforge/CurseForgeInstaller.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ public class CurseForgeInstaller {
8181
public static final String REPO_SUBDIR_MODPACKS = "modpacks";
8282
public static final String REPO_SUBDIR_MODS = "mods";
8383
public static final String REPO_SUBDIR_WORLDS = "worlds";
84-
private static final Duration BAD_FILE_DELAY = Duration.ofSeconds(5);
85-
public static final int BAD_FILE_ATTEMPTS = 3;
8684

8785
private final Path outputDir;
8886
private final Path resultsFile;
@@ -138,6 +136,12 @@ public class CurseForgeInstaller {
138136
@Getter @Setter
139137
int maxConcurrentDownloads;
140138

139+
@Getter @Setter
140+
int fileDownloadRetries = 5;
141+
142+
@Getter @Setter
143+
Duration fileDownloadRetryMinDelay = Duration.ofSeconds(5);
144+
141145
/**
142146
*/
143147
public void installFromModpackZip(Path modpackZip, String slug) {
@@ -776,18 +780,19 @@ private Mono<DownloadOrResolveResult> buildRetryableDownload(InstallContext con
776780
)
777781
// retry the deferred part above if one of the expected failure cases
778782
.retryWhen(
779-
Retry.backoff(BAD_FILE_ATTEMPTS, BAD_FILE_DELAY)
783+
Retry.backoff(fileDownloadRetries, fileDownloadRetryMinDelay)
780784
.filter(throwable ->
781785
throwable instanceof FileHashInvalidException ||
782786
throwable instanceof FailedRequestException ||
783787
throwable instanceof IOException ||
784788
throwable instanceof ChannelException
785789
)
786790
.doBeforeRetry(retrySignal ->
787-
log.warn("Retry #{} download of {} @ {}:{} due to {}",
791+
log.warn("Retry #{} download of {} @ {}:{} due to {}: {}",
788792
retrySignal.totalRetries() + 1,
789793
cfFile.getFileName(), modInfo.getName(), cfFile.getDisplayName(),
790-
retrySignal.failure().getClass().getSimpleName()
794+
retrySignal.failure().getClass().getSimpleName(),
795+
retrySignal.failure().getMessage()
791796
)
792797
)
793798
);

src/main/java/me/itzg/helpers/curseforge/InstallCurseForgeCommand.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.PrintWriter;
88
import java.nio.file.Files;
99
import java.nio.file.Path;
10+
import java.time.Duration;
1011
import java.util.List;
1112
import java.util.Set;
1213
import java.util.concurrent.Callable;
@@ -176,6 +177,16 @@ static class Listed {
176177
)
177178
int maxConcurrentDownloads;
178179

180+
@Option(names = "--file-download-retries", paramLabel = "COUNT",
181+
description = "Default is ${DEFAULT-VALUE}"
182+
)
183+
int fileDownloadRetries = 5;
184+
185+
@Option(names = "--file-download-retry-min-delay", paramLabel = "DURATION",
186+
description = "Default is ${DEFAULT-VALUE}"
187+
)
188+
Duration fileDownloadRetryMinDelay = Duration.ofSeconds(5);
189+
179190
@Override
180191
public Integer call() throws Exception {
181192
// https://www.curseforge.com/minecraft/modpacks/all-the-mods-8/files
@@ -214,7 +225,9 @@ public Integer call() throws Exception {
214225
.setDisableApiCaching(disableApiCaching)
215226
.setCacheArgs(cacheArgs)
216227
.setForgeUrlArgs(forgeUrlArgs)
217-
.setMaxConcurrentDownloads(maxConcurrentDownloads);
228+
.setMaxConcurrentDownloads(maxConcurrentDownloads)
229+
.setFileDownloadRetries(fileDownloadRetries)
230+
.setFileDownloadRetryMinDelay(fileDownloadRetryMinDelay);
218231

219232
if (apiBaseUrl != null) {
220233
installer.setApiBaseUrl(apiBaseUrl);

0 commit comments

Comments
 (0)