Exemplo n.º 1
0
  /** Schedules the next job execution. */
  public void schedule(JobScheduler jobScheduler) {
    if (jobScheduler.getActive()) {
      List<JobExecution> scheduledExecutions = findJobExecutions(jobScheduler, JobStatus.SCHEDULED);
      if (scheduledExecutions == null || scheduledExecutions.isEmpty()) {
        JobExecution nextJobExecution = jobScheduler.getNextJobExecution();

        if (nextJobExecution == null) {
          jobScheduler.setActive(Boolean.FALSE);
          em.merge(jobScheduler);
        } else {
          this.save(nextJobExecution);
        }
      } else {
        for (JobExecution jobExecution : scheduledExecutions) {
          if (findTimeout(jobExecution) == null) {
            Date timeout = schedule(jobExecution);
            jobExecution.setTimeout(timeout);
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  @Timeout
  public void startJob(Timer timer) {
    // Retrieves the job execution from the database.
    String jobExecutionId = (String) timer.getInfo();
    JobExecution currentJobExecution = find(jobExecutionId);
    if (currentJobExecution != null) {
      JobScheduler jobScheduler = currentJobExecution.getJobScheduler();

      // Starts the job execution.
      if (currentJobExecution.getStatus() == JobStatus.SCHEDULED) {
        currentJobExecution.setStartTime(Calendar.getInstance().getTime());
        startJob(currentJobExecution);
      }

      if (jobScheduler.getFrequencyType() != JobFrequencyType.ONCE
          && jobScheduler.getFrequencyType() != JobFrequencyType.INSTANT) {
        schedule(jobScheduler);
      } else {
        jobScheduler.setActive(Boolean.FALSE);
      }
    }
  }