public JobExecution launch(String jobName, JobParameters jobParameters)
      throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException,
          JobInstanceAlreadyCompleteException, JobParametersInvalidException {

    Job job = jobLocator.getJob(jobName);

    JobExecution lastJobExecution = jobRepository.getLastJobExecution(jobName, jobParameters);
    boolean restart = false;
    if (lastJobExecution != null) {
      BatchStatus status = lastJobExecution.getStatus();
      if (status.isUnsuccessful() && status != BatchStatus.ABANDONED) {
        restart = true;
      }
    }

    if (job.getJobParametersIncrementer() != null && !restart) {
      jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
    }

    JobExecution jobExecution = jobLauncher.run(job, jobParameters);

    if (jobExecution.isRunning()) {
      activeExecutions.add(jobExecution);
    }
    return jobExecution;
  }
 private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException {
   String jobIdentifier = job.getName();
   JobParameters jobParameters;
   List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);
   JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
   if (incrementer == null) {
     throw new JobParametersNotFoundException(
         "No job parameters incrementer found for job=" + jobIdentifier);
   }
   if (lastInstances.isEmpty()) {
     jobParameters = incrementer.getNext(new JobParameters());
     if (jobParameters == null) {
       throw new JobParametersNotFoundException(
           "No bootstrap parameters found from incrementer for job=" + jobIdentifier);
     }
   } else {
     jobParameters = incrementer.getNext(lastInstances.get(0).getJobParameters());
   }
   return jobParameters;
 }
Пример #3
0
  @Override
  public void runner() { // job runner
    log.info("RUNNER: PymkMain");
    try {
      Job job = (Job) PymkMain.getContext().getBean("pymkJob");
      JobParameters params =
          new JobParametersBuilder().addString("task", job.getName()).toJobParameters();
      jobLauncher.run(job, params);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // TaskScheduler scheduler = PymkMain.getContext().getBean("scheduler", TaskScheduler.class);
    // scheduler.schedule(new Runnable() {
    // public void run() {
    // System.out.println(new Date());
    // }
    // }, new Date());

    // PymkDbSyncMain r1 = PymkMain.getContext().getBean("pymkDbSyncMain", PymkDbSyncMain.class);
    // r1.runner();
    // AddressBookMain r2 = PymkMain.getContext().getBean("addressBookMain", AddressBookMain.class);
    // r2.runner();
  }