private static void waitForJobStatus(Job job, JobStatus status) { while (job.getStatus() != status) { LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(WAIT_INTERVAL_MILLIS)); } }
private static void waitForStatus(Job job, JobStatus expectedStatus) throws InterruptedException { for (JobStatus status; (status = job.getStatus()) != expectedStatus;) { System.out.println("Job is " + status + "..."); Thread.sleep(1); } System.out.println("Job is " + expectedStatus + "."); } }
private static void waitForComplete(Job job) { while (job.getStatus() != JobStatus.COMPLETED) { uncheckRun(() -> SECONDS.sleep(1)); } } }
private static void waitForComplete(Job job) { while (job.getStatus() != JobStatus.COMPLETED) { uncheckRun(() -> SECONDS.sleep(1)); } } }
private static void cancel(Job job) { job.cancel(); while (job.getStatus() != JobStatus.COMPLETED) { uncheckRun(() -> SECONDS.sleep(1)); } }
/** * <p>Run a Jet analysis job to examine the journal of updates to * HTTP sessions. As we don't want it to run for ever, give it a * second or two to do some work then end it. * </p> */ @ShellMethod(key = "ANALYSIS", value = "Analyse the orders") public void analyseSessions() throws Exception { IMap<String, Integer> sequenceMap = this.hazelcastInstance.getMap(Constants.IMAP_NAME_SEQUENCE); sequenceMap.clear(); Job analysisJob = this.jetInstance.newJob(SequenceAnalysis.build()); analysisJob.getFuture(); // Give the job time to do something int wait = 2; log.info("Sleep {} seconds", wait); TimeUnit.SECONDS.sleep(wait); if (analysisJob.getStatus() == JobStatus.RUNNING) { analysisJob.cancel(); } else { log.error("Job status {}", analysisJob.getStatus()); } System.out.printf("%d sequence%s found%n", sequenceMap.size(), (sequenceMap.size() == 1 ? "" : "s")); }
@Override public Job getJob(long jobId) { try { Job job = newJobProxy(jobId); // get the status for the side-effect of throwing an exception if the jobId is invalid job.getStatus(); return job; } catch (Throwable t) { if (peel(t) instanceof JobNotFoundException) { return null; } throw rethrow(t); } }
@Command( description = "Resumes a suspended job" ) public void resume( @Parameters(index = "0", paramLabel = "<job name or id>", description = "Name of the job to resume") String name ) throws IOException { runWithJet(jet -> { Job job = getJob(jet, name); if (job.getStatus() != JobStatus.SUSPENDED) { throw new RuntimeException("Job '" + name + "' is not suspended. Current state: " + job.getStatus()); } println("Resuming job " + formatJob(job) + "..."); job.resume(); waitForJobStatus(job, JobStatus.RUNNING); println("Job was successfully resumed."); }); }
@Nonnull @Override public Job newJobIfAbsent(@Nonnull DAG dag, @Nonnull JobConfig config) { if (config.getName() == null) { return newJob(dag, config); } else { while (true) { Job job = getJob(config.getName()); if (job != null) { JobStatus status = job.getStatus(); if (status != JobStatus.FAILED && status != JobStatus.COMPLETED) { return job; } } try { return newJob(dag, config); } catch (JobAlreadyExistsException e) { logFine(getLogger(), "Could not submit job with duplicate name: %s", config.getName()); } } } }
System.out.println("Status: " + job.getStatus());
while (job.getStatus() != JobStatus.RUNNING) { Thread.sleep(1);
@Test public void test_listJobs() { // Given Job job = newJob(); // When run("jobs"); // Then String actual = captureOut(); assertContains(actual, job.getName()); assertContains(actual, job.getIdString()); assertContains(actual, job.getStatus().toString()); }