Last active
November 22, 2017 16:35
-
-
Save tteggel/3c95f7e84c91614807dadf1f61c3cc06 to your computer and use it in GitHub Desktop.
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
public void book3(TripReq input) { | |
Flow f = Flows.currentFlow(); | |
FlowFuture<BookingRes> flightFuture = | |
f.invokeFunction("./flight/book", input.flight, BookingRes.class); | |
FlowFuture<BookingRes> hotelFuture = | |
f.invokeFunction("./hotel/book", input.hotel, BookingRes.class); | |
FlowFuture<BookingRes> carFuture = | |
f.invokeFunction("./car/book", input.carRental, BookingRes.class); | |
flightFuture.thenCompose( | |
(flightRes) -> hotelFuture.thenCompose( | |
(hotelRes) -> carFuture.whenComplete( | |
(carRes, e) -> EmailReq.sendSuccessMail(flightRes, hotelRes, carRes) | |
) | |
.exceptionallyCompose( (e) -> retryCancel("./car/cancel", input.carRental, e) ) | |
) | |
.exceptionallyCompose( (e) -> retryCancel("./hotel/cancel", input.hotel, e) ) | |
) | |
.exceptionallyCompose( (e) -> retryCancel("./flight/cancel", input.flight, e) ) | |
.exceptionally( (err) -> {EmailReq.sendFailEmail(); return null;} ); | |
} | |
private static FlowFuture<BookingRes> retryCancel(String cancelFn, Object input, Throwable e) { | |
Retry.exponentialWithJitter( | |
() -> Flows.currentFlow().invokeFunction(cancelFn, input, BookingRes.class)); | |
return Flows.currentFlow().failedFuture(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment