Skip to content

Instantly share code, notes, and snippets.

@rockpunk
Created September 14, 2013 06:56
Show Gist options
  • Save rockpunk/6559481 to your computer and use it in GitHub Desktop.
Save rockpunk/6559481 to your computer and use it in GitHub Desktop.
JobSummary.Status lastStatus = null;
while( loop ) {
Thread.sleep(POLL_INTERVAL);
JobSummary.Status status = client.showJobStatus(job);
switch( status ) {
case SUCCESS:
loop = false;
break;
case KILLED:
throw new Exception("TreasureData job was terminated. " + "(jobID="+jobId+")");
case ERROR:
ShowJobRequest jsReq = new ShowJobRequest(job);
ShowJobResult res = client.showJob(jsReq);
JobSummary js = res.getJob();
String err = String.format("TreasureData job failed in status ERROR: %s (jobID=%s)",
js.getDebug().getStderr(),
jobId);
throw new Exception(err);
case UNKNOWN:
// don't know what to do here.
case BOOTING:
case QUEUED:
case RUNNING:
default:
if( status != lastStatus ) {
lastStatus = status;
waitTime = POLL_INTERVAL;
}
else {
waitTime += POLL_INTERVAL;
}
if( timeout > 0 && waitTime > timeout ) {
_log.debug("Waited {}ms in status {}, killing jobid = {}", new Object[] {waitTime, lastStatus, jobId});
client.killJob(job);
throw new Exception("TreasureData job timed out after " + (long)(timeout/1000) + " seconds (jobId="+jobId+"). Aborting job.");
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment