@class Job
@classdesc Potentially long-running background job.

@see {@link Scan#background}
@see {@link Query#background}
180135
function Job (client, jobID, module) {
  this.client = client
  this.jobID = jobID
  this.module = module
}
1339592
@Override
	public JobStatus getJobStatus(long instanceId) {
		logger.entering(CLASSNAME, "getJobStatus", instanceId);
		Connection conn = null;
		PreparedStatement statement = null;
		ResultSet rs = null;
		RuntimeJobExecution jobExecution = null;
		String query = "SELECT obj FROM jobstatus WHERE id = ?";
		JobStatus jobStatus = null;

		try {
			conn = getConnection();
			statement = conn.prepareStatement(query);
			statement.setLong(1, instanceId);
			rs = statement.executeQuery();
			if(rs.next()) {
				jobStatus = (JobStatus)deserializeObject(rs.getBytes(1));
			}
		} catch (SQLException e) {
			throw new PersistenceException(e);
		} catch (IOException e) {
			throw new PersistenceException(e);
		} catch (ClassNotFoundException e) {
			throw new PersistenceException(e);
		} finally {
			cleanupConnection(conn, rs, statement);
		}
		logger.exiting(CLASSNAME, "getJobStatus", jobStatus);
		return jobStatus;
	}
1350969
@Nonnull
  public TriggerBuilder <T> forJob (@Nonnull final IJobDetail jobDetail)
  {
    final JobKey k = jobDetail.getKey ();
    if (k.getName () == null)
      throw new IllegalArgumentException ("The given job has not yet had a name assigned to it.");
    m_aJobKey = k;
    return this;
  }
806022
protected Object execute(final Job job, final String curQueue, final Object instance) throws Exception {
        if (instance instanceof WorkerAware) {
            ((WorkerAware) instance).setWorker(this);
        }
        this.listenerDelegate.fireEvent(JOB_EXECUTE, this, curQueue, job, instance, null, null);
        final Object result;
        if (instance instanceof Callable) {
            result = ((Callable<?>) instance).call(); // The job is executing!
        } else if (instance instanceof Runnable) {
            ((Runnable) instance).run(); // The job is executing!
            result = null;
        } else { // Should never happen since we're testing the class earlier
            throw new ClassCastException(
                    "Instance must be a Runnable or a Callable: " + instance.getClass().getName() + " - " + instance);
        }
        return result;
    }
1237960
public Job getJobFromId(String jobName) {
    // [START ]
    JobId jobIdObject = JobId.of(jobName);
    Job job = bigquery.getJob(jobIdObject);
    if (job == null) {
      // job was not found
    }
    // [END ]
    return job;
  }
290682
@Override
    public JobDetail retrieveJob(final JobKey jobKey) throws JobPersistenceException {
        return doWithLock(new LockCallback<JobDetail>() {
            @Override
            public JobDetail doWithLock(JedisCommands jedis) throws JobPersistenceException {
                try {
                    return storage.retrieveJob(jobKey, jedis);
                } catch (ClassNotFoundException e) {
                    throw new JobPersistenceException("Error retrieving job: " + e.getMessage(), e);
                }
            }
        }, "Could not retrieve job.");
    }
28863
@Override
    public List<JobInstance> getJobs(Query query)
    {
        return JqmClientFactory.getClient().getJobs(query);
    }
963021
@Override
  protected RunningJob createRunningJob(JobID jobId, TaskInProgress tip)
      throws IOException {
    CoronaSessionInfo info = (CoronaSessionInfo)(tip.getExtensible());
    // JobClient will be set by JobTrackerReporter thread later
    RunningJob rJob = new RunningJob(jobId, null, info);
    JobTrackerReporter reporter = new JobTrackerReporter(rJob,
        info.getJobTrackerAddr(), info.getSecondaryTracker(),
        info.getSessionHandle());
    reporter.setName("JobTrackerReporter for " + jobId);
    // Start the heartbeat to the jobtracker
    reporter.start();
    jobTrackerReporters.put(jobId, reporter);
    return rJob;
  }
327233
@Override
    public JobIntentService.GenericWorkItem dequeueWork() {
        JobWorkItem work = null;
        synchronized (mLock) {
            if (mParams == null) {
                return null;
            }
            try {
                work = mParams.dequeueWork();
            } catch (SecurityException se) {
                //ignore
                se.printStackTrace();
            }
        }
        if (work != null) {
            work.getIntent().setExtrasClassLoader(mService.getClassLoader());
            return new WrapperWorkItem(work);
        } else {
            return null;
        }
    }
1272037
@NotOnCli
  public JobExecutionResult run() throws InterruptedException, TimeoutException, ExecutionException {
    JobExecutionDriver jobDriver = runAsync();
    return jobDriver.get(this.jobTimeout.getTimeout(), this.jobTimeout.getTimeUnit());
  }
1294858
private synchronized RunningJobImpl get(final String jobIdentifier) {
    final RunningJobImpl result = this.jobs.get(jobIdentifier);
    if (null == result) {
      throw new RuntimeException("Trying to get a RunningJob that is unknown: " + jobIdentifier);
    }
    return result;
  }
1241389
@Override
    public final Job queueIn(final Job job, final long millis) {
        return pushAt(job, System.currentTimeMillis() + millis);
    }
116659
@Override
    public Run<?, ?> resolve(Job<?, ?> job) {
        File f = getPermalinkFile(job);
        Run<?,?> b=null;

        try {
            String target = readSymlink(f);
            if (target!=null) {
                int n = Integer.parseInt(Util.getFileName(target));
                if (n==RESOLVES_TO_NONE)  return null;

                b = job.getBuildByNumber(n);
                if (b!=null && apply(b))
                    return b;   // found it (in the most efficient way possible)

                // the cache is stale. start the search
                if (b==null)
                     b=job.getNearestOldBuild(n);
            }
        } catch (InterruptedException e) {
            LOGGER.log(Level.WARNING, "Failed to read permalink cache:" + f, e);
            // if we fail to read the cache, fall back to the re-computation
        } catch (NumberFormatException e) { 
            LOGGER.log(Level.WARNING, "Failed to parse the build number in the permalink cache:" + f, e);
            // if we fail to read the cache, fall back to the re-computation
        } catch (IOException e) {
            // this happens when the symlink doesn't exist
            // (and it cannot be distinguished from the case when the actual I/O error happened
        }

        if (b==null) {
            // no cache
            b = job.getLastBuild();
        }

        // start from the build 'b' and locate the build that matches the criteria going back in time
        b = find(b);

        updateCache(job,b);
        return b;
    }
1176809
protected RunnerResult doRun(Class<? extends LaJob> jobType, LaJobRuntime runtime) {
        // similar to async manager's process
        arrangeThreadCacheContext(runtime);
        arrangePreparedAccessContext(runtime);
        arrangeCallbackContext(runtime);
        final Object variousPreparedObj = prepareVariousContext(runtime);
        final long before = showRunning(runtime);
        Throwable cause = null;
        try {
            debugFw(runtime, "...Calling try clause of job runner");
            hookBefore(runtime);
            debugFw(runtime, "...Calling actuallyRun() of job runner");
            actuallyRun(jobType, runtime);
        } catch (Throwable e) {
            debugFw(runtime, "...Calling catch clause of job runner: {}", e.getClass().getSimpleName());
            final Throwable filtered = filterCause(e);
            cause = filtered;
            showJobException(runtime, before, filtered);
        } finally {
            debugFw(runtime, "...Calling finally clause of job runner");
            hookFinally(runtime, OptionalThing.ofNullable(cause, () -> {
                throw new IllegalStateException("Not found the cause: " + runtime);
            }));
            showFinishing(runtime, before, cause); // should be before clearing because of using them
            clearVariousContext(runtime, variousPreparedObj);
            clearPreparedAccessContext();
            clearCallbackContext();
            clearThreadCacheContext();
        }
        debugFw(runtime, "...Calling createRunnerResult() of job runner");
        return createRunnerResult(runtime, cause);
    }
1207433
public void run() {
    while (running) {
      try {
        cleanUpInitializedJobsList();
        selectJobsToInitialize();
        if (!this.isInterrupted()) {
          Thread.sleep(sleepInterval);
        }
      } catch (InterruptedException e) {
        LOG.error("Job Initialization poller interrupted"
            + StringUtils.stringifyException(e));
      }
    }
  }
1066811
public int run(String jobName, String[] args) {
        int status = -1;

        try {
            Class<? extends SimpleJobTool> clazz = jobMap.get(jobName);
            if (clazz == null) {
                log.error("Tool " + jobName + " class not found.");
                return status;
            }
            status =  ToolRunner.run(clazz.newInstance(), args);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
        }

        return status;
    }
997100
private void runJobLauncherLoop() throws JobException {
    try {
      while (true) {
        currentJobLauncher = this.jobScheduler.buildJobLauncher(jobProps);
        // in "run once" case, job scheduler will remove current job from the scheduler
        boolean isEarlyStopped = this.jobScheduler.runJob(jobProps, jobListener, currentJobLauncher);
        boolean isRetriggerEnabled = this.isRetriggeringEnabled();
        if (isEarlyStopped && isRetriggerEnabled) {
          log.info("Job {} will be re-triggered.", jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY));
        } else {
          break;
        }
        currentJobLauncher = null;
      }
    } catch (Exception e) {
      log.error("Failed to run job {}", jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY), e);
      throw new JobException("Failed to run job " + jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY), e);
    }
  }