Last active
May 20, 2018 23:34
-
-
Save pdk/aa086f70a1b6fdddde87514c78cb3b70 to your computer and use it in GitHub Desktop.
After cleaning up exception handling
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 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