Exemple #1
0
 public boolean resumeJob(JobKey jobKey) {
   try {
     scheduler.resumeJob(jobKey);
     return true;
   } catch (SchedulerException e) {
     logger.error("调度器恢复JOB异常:" + e.getMessage());
     return false;
   }
 }
 /** resume a job with the given jobId assuming the job is in the default quartz group */
 @Override
 public void resumeJob(String jobId) {
   try {
     sched.resumeJob(jobKey(jobId, Scheduler.DEFAULT_GROUP));
   } catch (SchedulerException se) {
     log.error("failed to pause a job with id={}: {}", jobId, se.getMessage());
     log.debug("Exception", se);
   }
 }
  public static void main(String[] args) throws Exception {

    JobKey jobKeyA = new JobKey("jobA", "group1");
    JobDetail jobA = JobBuilder.newJob(JobA.class).withIdentity(jobKeyA).build();

    JobKey jobKeyB = new JobKey("jobB", "group1");
    JobDetail jobB = JobBuilder.newJob(JobB.class).withIdentity(jobKeyB).build();

    JobKey jobKeyC = new JobKey("jobC", "group1");
    JobDetail jobC = JobBuilder.newJob(JobC.class).withIdentity(jobKeyC).build();

    Trigger trigger1 =
        TriggerBuilder.newTrigger()
            .withIdentity("dummyTriggerName1", "group1")
            .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
            .build();

    Trigger trigger2 =
        TriggerBuilder.newTrigger()
            .withIdentity("dummyTriggerName2", "group1")
            .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
            .build();

    Trigger trigger3 =
        TriggerBuilder.newTrigger()
            .withIdentity("dummyTriggerName3", "group1")
            .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
            .build();

    StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
    schedulerFactory.initialize("resources/quartz.properties");
    Scheduler scheduler = schedulerFactory.getScheduler();

    scheduler.start();
    //    	scheduler.scheduleJob(jobA, trigger1);
    //    	scheduler.scheduleJob(jobB, trigger2);
    //    	scheduler.scheduleJob(jobC, trigger3);

    scheduler.deleteJob(jobKeyA);
    //    	scheduler.pauseJob(jobKeyB);
    scheduler.resumeJob(jobKeyB);
  }
  @Override
  public void resume(String jobName, String groupName, StorageType storageType)
      throws SchedulerException {

    try {
      Scheduler scheduler = getScheduler(storageType);

      jobName = fixMaxLength(jobName, _jobNameMaxLength, storageType);
      groupName = fixMaxLength(groupName, _groupNameMaxLength, storageType);

      JobKey jobKey = new JobKey(jobName, groupName);

      scheduler.resumeJob(jobKey);

      updateJobState(scheduler, jobKey, TriggerState.NORMAL, false);
    } catch (Exception e) {
      throw new SchedulerException(
          "Unable to resume job {jobName=" + jobName + ", groupName=" + groupName + "}", e);
    }
  }
 public void resumeJob(JobKey jobKey) throws SchedulerException {
   quartzScheduler.resumeJob(jobKey);
 }
  public void jobAdded(JobDetail jobDetail) {
    TrackNRestartMessageKind.ITNRPLUGIN0003.format(jobDetail.getKey());
    JobKey jobKey = jobDetail.getKey();
    JobDataMap currentJobDataMap = jobDetail.getJobDataMap();
    String restart = currentJobDataMap.getString(RESTARTED_FIRE_INSTANCE_ID);
    try {
      if (fetchJob(getNonManagedTXConnection(), jobKey)) { // group.job exists
        if (restart
            == null) { // simple tracking mode but such an initial execution of this job has already
          // been recorded
          TrackNRestartMessageKind.ITNRPLUGIN0004.format(jobKey);
          TrackNRestartMessageKind.WTNRPLUGIN0005.format(jobKey);
        } else {
          if (restart.trim().equals("_LAST_")) { // Retrieve last execution to restart it
            restart = fetchJobExecLast(getNonManagedTXConnection(), jobKey);
            if (restart != null) {

              jobDetail.getJobBuilder().usingJobData(RESTARTED_FIRE_INSTANCE_ID, restart);
              jobDetail.getJobBuilder().usingJobData(JOB_IDENTIFICATION_COMPLETE, false);

              TrackNRestartMessageKind.ITNRPLUGIN0006.format(jobKey, restart);
              scheduler.pauseJob(jobKey);
              scheduler.addJob(jobDetail, true); // WARNING recursivity !

            } else {
              breakJob(jobKey, TrackNRestartMessageKind.ETNRPLUGIN0007.format(jobKey, restart));
            }
          } else { // Retrieve numbered execution to restart it
            if (!currentJobDataMap.getBoolean(
                JOB_IDENTIFICATION_COMPLETE)) { // to break recursivity
              if (fetchJobExec(getNonManagedTXConnection(), jobKey, restart)) { // found

                JobDataMap previousJobDataMap =
                    (JobDataMap)
                        getJobExecParams(
                            getNonManagedTXConnection(),
                            jobKey,
                            restart); // retrieve JDM from job to restart

                completeWithMissingParams(currentJobDataMap, previousJobDataMap);

                jobDetail.getJobBuilder().usingJobData(JOB_IDENTIFICATION_COMPLETE, true);

                TrackNRestartMessageKind.ITNRPLUGIN0010.format(jobKey, restart);
                scheduler.addJob(jobDetail, true); // WARNING recursivity !

              } else { // not found
                breakJob(jobKey, TrackNRestartMessageKind.ETNRPLUGIN0007.format(jobKey, restart));
              }
              scheduler.resumeJob(jobKey);
            }
          }
        }
      } else { // group.job doesn't exist
        if (restart == null) { // simple tracking mode
          TrackNRestartMessageKind.ITNRPLUGIN0004.format(jobKey);
        } else { // inconsistent restarting mode
          breakJob(jobKey, TrackNRestartMessageKind.ETNRPLUGIN0013.format(jobKey, restart));
        }
      }
    } catch (TrackNRestartException e) {
      throw e;
    } catch (Exception e) {
      try {
        breakJob(jobKey, TrackNRestartMessageKind.ETNRPLUGIN0002.format(e));
        //				e.printStackTrace();
        //				scheduler.deleteJob(jobKey);
      } catch (SchedulerException e1) {
        getLog().error("Deleting " + jobKey + " caused exception.", e);
      }
    }
  }