Skip to content

Commit

Permalink
Adding error handling if no events.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Dec 9, 2024
1 parent 49c4522 commit 1a7d272
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,15 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli

// TODO: Run this in a separate thread.
try {

judgmentCount = coecClickModel.calculateJudgments();
} catch (Exception e) {
throw new RuntimeException(e);

if(judgmentCount == 0) {
return restChannel -> restChannel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, "{\"error\": \"No judgments were created. Check the queries and events data.\"}"));
}

} catch (Exception ex) {
throw new RuntimeException("Unable to generate judgments.", ex);
}

final long elapsedTime = System.currentTimeMillis() - startTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ public long calculateCoec(final Map<Integer, Double> rankAggregatedClickThrough,
}

if(parameters.isPersist()) {
openSearchHelper.indexJudgments(judgments);
if(!judgments.isEmpty()) {
openSearchHelper.indexJudgments(judgments);
} else {
LOGGER.warn("Judgments were not indexed because no judgments were created. Check the events and query source data.");
}
}

LOGGER.debug("Persisted number of judgments: {}", judgments.size());
Expand Down

0 comments on commit 1a7d272

Please sign in to comment.