Last active
November 4, 2021 13:00
-
-
Save jvorhauer/bf70831dec1bc07eb05e43779c718b88 to your computer and use it in GitHub Desktop.
[mono-with-retry] Repeat a GET if the Mono is empty #java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/questions/55923326/conditional-repeat-or-retry-on-mono-with-webclient-from-spring-webflux | |
private Either<Fault, String> poll(final String id) { | |
JobResponse jr = webClient | |
.get() | |
.uri(baseUrl + "/jobs/" + id + "?f=json") | |
.retrieve() | |
.bodyToMono(JobResponse.class) | |
.filter(JobResponse::done) | |
.repeatWhenEmpty( | |
Repeat.onlyIf(ctx -> true).timeout(Duration.ofSeconds(10L)) | |
).block(); | |
return jr == null ? Either.left(Fault.serverSide("???")) : Either.right(jr.getJobId()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment