Created
September 14, 2013 06:56
-
-
Save rockpunk/6559481 to your computer and use it in GitHub Desktop.
Revisions
-
rockpunk created this gist
Sep 14, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ 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; } }