Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
vista-snippet.java
public void handleRequest(ScrapeReq input) throws Exception {
FlowFuture<ScrapeResp> scrapes = currentFlow().invokeFunction("./scraper", input, ScrapeResp.class);
scrapes.thenCompose(resp -> {
List<ScrapeResp.ScrapeResult> results = resp.result;
List<FlowFuture<?>> pendingTasks = results
.stream()
.map(scrapeResult -> {
log.info("starting image detection on {}", scrapeResult.image_url);
String id = scrapeResult.id;
return currentFlow()
.invokeFunction("./detect-plates", new DetectPlateReq(scrapeResult.image_url, "us"), DetectPlateResp.class)
.thenCompose((plateResp) -> {
if (!plateResp.got_plate) {
log.info("No plates found in {}", scrapeResult.image_url);
// bug
return currentFlow().completedValue(null);
}
log.info("Got plate {} in {}", plateResp.plate, scrapeResult.image_url);
return currentFlow()
.invokeFunction("./draw", new DrawReq(id, scrapeResult.image_url, plateResp.rectangles,"300x300"), DrawResp.class)
.thenCompose((drawResp) -> {
log.info("Got draw response {} ", drawResp.image_url);
return currentFlow().allOf(
currentFlow().invokeFunction("./alert", new AlertReq(plateResp.plate, drawResp.image_url)),
Slack.postImageToSlack(slackChannel,
drawResp.image_url,
"plate",
"Found plate: " + plateResp.plate,
"Have you seen this car?"));
}
);
});
}).collect(Collectors.toList());
return currentFlow()
.allOf(pendingTasks.toArray(new FlowFuture[pendingTasks.size()]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.