Skip to content

Instantly share code, notes, and snippets.

@rockpunk
Created September 14, 2013 06:56
Show Gist options
  • Select an option

  • Save rockpunk/6559481 to your computer and use it in GitHub Desktop.

Select an option

Save rockpunk/6559481 to your computer and use it in GitHub Desktop.

Revisions

  1. rockpunk created this gist Sep 14, 2013.
    39 changes: 39 additions & 0 deletions gistfile1.java
    Original 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;
    }
    }