Skip to content

Commit 651fd14

Browse files
authored
fabric: retry loader version lookup (#543)
1 parent 7f60879 commit 651fd14

File tree

6 files changed

+49
-13
lines changed

6 files changed

+49
-13
lines changed

src/main/java/me/itzg/helpers/McImageHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,4 @@ public Integer call() throws Exception {
239239
return ExitCode.OK;
240240
}
241241
}
242-
}
242+
}

src/main/java/me/itzg/helpers/fabric/FabricMetaClient.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ public class FabricMetaClient {
1919

2020
private final SharedFetch sharedFetch;
2121
private final UriBuilder uriBuilder;
22+
23+
/**
24+
* Retry attempts for metadata, non-downloads
25+
*/
26+
@Setter
27+
private long retryMaxAttempts = 5;
28+
/**
29+
* Retry minimum backoff for metadata, non-downloads
30+
*/
31+
@Setter
32+
private Duration retryMinBackoff = Duration.ofMillis(500);
33+
2234
@Setter
2335
private int downloadRetryMaxAttempts = 5;
2436
@Setter
@@ -59,7 +71,9 @@ else if (isSnapshot(version)) {
5971
return findFirst(versionEntries, versionEntry -> versionEntry.getVersion().equalsIgnoreCase(version))
6072
.switchIfEmpty(Mono.error(() -> new GenericException("Unable to find requested version")));
6173
}
62-
});
74+
})
75+
.retryWhen(Retry.backoff(retryMaxAttempts, retryMinBackoff).filter(IOException.class::isInstance))
76+
.checkpoint();
6377
}
6478

6579
private static boolean isSnapshot(@Nullable String version) {
@@ -91,7 +105,9 @@ public Mono<String> resolveLoaderVersion(String minecraftVersion, String loaderV
91105
.getLoader();
92106

93107
return Mono.just(loader.getVersion());
94-
});
108+
})
109+
.retryWhen(Retry.backoff(retryMaxAttempts, retryMinBackoff).filter(IOException.class::isInstance))
110+
.checkpoint();
95111
}
96112

97113
public Mono<String> resolveInstallerVersion(String installerVersion) {
@@ -111,7 +127,9 @@ public Mono<String> resolveInstallerVersion(String installerVersion) {
111127
.orElseGet(
112128
() -> Mono.error(new GenericException("Failed to find stable installer from " + uriBuilder.getBaseUrl()))
113129
)
114-
);
130+
)
131+
.retryWhen(Retry.backoff(retryMaxAttempts, retryMinBackoff).filter(IOException.class::isInstance))
132+
.checkpoint();
115133
}
116134

117135
public Mono<Path> downloadLauncher(

src/main/java/me/itzg/helpers/http/ObjectFetchBuilder.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.fasterxml.jackson.databind.ObjectReader;
5+
import java.io.IOException;
6+
import java.util.List;
57
import lombok.extern.slf4j.Slf4j;
6-
import me.itzg.helpers.errors.GenericException;
78
import reactor.core.publisher.Mono;
89
import reactor.core.scheduler.Schedulers;
910
import reactor.netty.ByteBufMono;
1011
import reactor.netty.http.client.HttpClient;
1112
import reactor.netty.http.client.HttpClientResponse;
1213

13-
import java.io.IOException;
14-
import java.util.List;
15-
1614
@Slf4j
1715
public class ObjectFetchBuilder<T> extends FetchBuilderBase<ObjectFetchBuilder<T>>
1816
implements RequestResponseAssembler<T>
@@ -84,7 +82,7 @@ private <R> Mono<R> handleResponse(HttpClientResponse resp, ByteBufMono bodyMono
8482
try {
8583
return Mono.just(reader.readValue(inputStream));
8684
} catch (IOException e) {
87-
return Mono.error(new GenericException(
85+
return Mono.error(new ResponseParsingException(
8886
"Failed to parse response body into " +
8987
(listOf ? "list of " + type : type),
9088
e
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package me.itzg.helpers.http;
2+
3+
import java.io.IOException;
4+
5+
public class ResponseParsingException extends IOException {
6+
7+
public ResponseParsingException(String message, Throwable cause) {
8+
super(message, cause);
9+
}
10+
}

src/main/java/me/itzg/helpers/modrinth/ModrinthApiClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
import reactor.core.publisher.Mono;
3232
import reactor.core.scheduler.Schedulers;
3333

34+
/**
35+
* Provides a client for <a href="https://docs.modrinth.com/api/">Modrinth Labrinth API</a>
36+
*/
3437
@Slf4j
3538
public class ModrinthApiClient implements AutoCloseable {
3639

src/main/java/me/itzg/helpers/modrinth/model/VersionFile.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
import java.util.Map;
44
import lombok.Data;
55

6+
/**
7+
* Refer to <code>files</code> of <a href="https://docs.modrinth.com/api/operations/getversion/#200">getversion</a>
8+
*/
69
@Data
710
public class VersionFile {
8-
Map<String,String> hashes;
911

10-
String url;
12+
/**
13+
* key is either sha512 or sha1
14+
*/
15+
Map<String, String> hashes;
1116

12-
String filename;
17+
String url;
1318

14-
boolean primary;
19+
String filename;
20+
21+
boolean primary;
1522
}

0 commit comments

Comments
 (0)