Skip to content

Instantly share code, notes, and snippets.

@pdk
Last active May 20, 2018 23:34
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 pdk/aa086f70a1b6fdddde87514c78cb3b70 to your computer and use it in GitHub Desktop.
Save pdk/aa086f70a1b6fdddde87514c78cb3b70 to your computer and use it in GitHub Desktop.
After cleaning up exception handling
public boolean isJobReady(DataSource dataSource, DateTime batchDate, Map<String, String> params)
throws BatchJobFailureException {
String alphaBatchId = params.get("batchId");
checkNotNull(alphaBatchId, "batchId is required to check status of a Blorp batch");
BlorpAlphaClient client = lookupClient(dataSource);
BatchResponse response;
try {
response = client.status(alphaBatchId);
} catch (IOException e) {
// Having a "temporary" communication problem. Try again, later.
log.exception("Alpha batchId={}, status=unknown, communication problem: {}", e, alphaBatchId, e.getMessage());
return false;
}
boolean isJobComplete = batchQueryStatusCompleted(alphaBatchId, response.status);
logJobStatusCheck(alphaBatchId, response.status, String.valueOf(isJobComplete));
return isJobComplete;
}
public static boolean batchQueryStatusCompleted(String alphaBatchId, String status) throws BatchJobFailureException {
switch (status.toLowerCase()) {
case RESPONSE_SUBMITTED:
case RESPONSE_EXECUTING:
return false;
case RESPONSE_COMPLETED:
return true;
case RESPONSE_ERROR:
case RESPONSE_ABORTED:
case RESPONSE_CANCELLED:
logJobStatusCheck(alphaBatchId, status, "failed");
throw new BatchJobFailureException("Zuora failed to complete batch job. status=" + status);
default:
// Might be better to throw an exception here.
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment