Skip to content

Instantly share code, notes, and snippets.

@mjg123
Last active February 14, 2018 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjg123/8198a1311f4e8fa3b8376e93d24cafb1 to your computer and use it in GitHub Desktop.
Save mjg123/8198a1311f4e8fa3b8376e93d24cafb1 to your computer and use it in GitHub Desktop.
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