Skip to content

Commit

Permalink
fabric: retry download when IO exception (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
itzg authored Feb 2, 2025
1 parent 6e228be commit bc56415
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void installUsingVersions(
resolvedLoaderVersion,
resolvedInstallerVersion
))
.checkpoint("downloadResolvedLauncher")
)
)
.block();
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/me/itzg/helpers/fabric/FabricMetaClient.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package me.itzg.helpers.fabric;

import java.io.IOException;
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import java.util.function.Predicate;
import lombok.Setter;
import me.itzg.helpers.errors.GenericException;
import me.itzg.helpers.http.FileDownloadStatusHandler;
import me.itzg.helpers.http.SharedFetch;
import me.itzg.helpers.http.UriBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;

public class FabricMetaClient {

private final SharedFetch sharedFetch;
private final UriBuilder uriBuilder;
@Setter
private int downloadRetryMaxAttempts = 5;
@Setter
private Duration downloadRetryMinBackoff = Duration.ofMillis(500);

public FabricMetaClient(SharedFetch sharedFetch, String fabricMetaBaseUrl) {
this.sharedFetch = sharedFetch;
Expand Down Expand Up @@ -106,7 +114,9 @@ public Mono<Path> downloadLauncher(
)
.toDirectory(outputDir)
.handleStatus(statusHandler)
.assemble();
.assemble()
.retryWhen(Retry.backoff(downloadRetryMaxAttempts, downloadRetryMinBackoff).filter(IOException.class::isInstance))
.checkpoint("downloadLauncher");
}

@NotNull
Expand Down

0 comments on commit bc56415

Please sign in to comment.