@Override public Job cancel(String jobId) { Job job = jobs.remove(jobId); job.abort(); return job; }
public void run() { try { onJobStarted(); completeWithSuccess(jobRun()); } catch (Throwable e) { LOGGER.error("Job failed", e); completeWithError(e); } finally { onJobEnded(); } }
private synchronized void completeWithError(Throwable error) { setException(error); errorMessage = getJobExceptionStack(error); }
if (runningJob.isAborted()) { runningJob.setStatus(Job.Status.ABORT); runningJob.aborted = false; return; LOGGER.info("Job " + runningJob.getId() + " started by scheduler " + name); runningJob.setStatus(Job.Status.RUNNING); runningJob.run(); Object jobResult = runningJob.getReturn(); if (runningJob.isAborted()) { runningJob.setStatus(Job.Status.ABORT); LOGGER.debug("Job Aborted, " + runningJob.getId() + ", " + runningJob.getErrorMessage()); } else if (runningJob.getException() != null) { LOGGER.debug("Job Error, " + runningJob.getId() + ", " + runningJob.getReturn()); runningJob.setStatus(Job.Status.ERROR); } else if (jobResult != null && jobResult instanceof InterpreterResult && ((InterpreterResult) jobResult).code() == InterpreterResult.Code.ERROR) { LOGGER.debug("Job Error, " + runningJob.getId() + ", " + runningJob.getReturn()); runningJob.setStatus(Job.Status.ERROR); } else { LOGGER.debug("Job Finished, " + runningJob.getId() + ", Result: " + runningJob.getReturn()); runningJob.setStatus(Job.Status.FINISHED);
@Override public void run() { try { while (!Thread.interrupted()) { JobListener listener = job.getListener(); if (listener != null) { try { if (job.isRunning()) { listener.onProgressUpdate(job, job.progress()); } } catch (Exception e) { logger.error("Can not get or update progress", e); } } Thread.sleep(intervalMs); } } catch (InterruptedException ignored) { // just ignore this exception } } }
@Override public void cancel(String sessionId, String className, RemoteInterpreterContext interpreterContext) throws TException { logger.info("cancel {} {}", className, interpreterContext.getParagraphId()); Interpreter intp = getInterpreter(sessionId, className); String jobId = interpreterContext.getParagraphId(); Job job = intp.getScheduler().getJob(jobId); if (job != null && job.getStatus() == Status.PENDING) { job.setStatus(Status.ABORT); } else { try { intp.cancel(convert(interpreterContext, null)); } catch (InterpreterException e) { throw new TException("Fail to cancel", e); } } }
public JobProgressPoller(Job job, long intervalMs) { super("JobProgressPoller, jobId=" + job.getId()); this.job = job; if (intervalMs < 0) { throw new IllegalArgumentException("polling interval can't be " + intervalMs); } this.intervalMs = intervalMs == 0 ? DEFAULT_INTERVAL_MSEC : intervalMs; }
@Override public String getStatus(String sessionId, String jobId) throws TException { if (interpreterGroup == null) { return Status.UNKNOWN.name(); } synchronized (interpreterGroup) { List<Interpreter> interpreters = interpreterGroup.get(sessionId); if (interpreters == null) { logger.info("getStatus:" + Status.UNKNOWN.name()); return Status.UNKNOWN.name(); } for (Interpreter intp : interpreters) { Job job = intp.getScheduler().getJob(jobId); logger.info("job:" + job); if (job != null) { logger.info("getStatus: " + job.getStatus().name()); return job.getStatus().name(); } } } logger.info("getStatus:" + Status.UNKNOWN.name()); return Status.UNKNOWN.name(); }