如何检查哪个Quartz Scheduler作业未运行

时间:2017-02-03 10:58:29

标签: java spring triggers quartz-scheduler

我有以下代码用于检查哪个石英调度程序作业正在运行。它还向我发送了一封运行调度程序作业列表的电子邮件。但我不知道它没有返回正在运行的所有调度程序作业。现在我只想知道那些有问题,已停止且未运行的调度程序作业。我在我的生产环境中发现了一个关键问题,我发现一些调度程序作业没有运行,但我真的不知道它是哪个调度程序工作。

public String getPrintJobs() {
  StringBuilder sb = new StringBuilder();
  try {
   sb.append("Quartz Jobs\r\n\r\n");

   Scheduler scheduler = this.getJobScheduler();
         // All scheduled jobs
         for (String groupName : scheduler.getJobGroupNames()) {
             for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
                 JobDetail jobDetail = scheduler.getJobDetail(jobKey);
                 final List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
     Date nextFireTime = null;
     int priority = 5;
              if (triggers.size() > 0)
              {
                  nextFireTime = triggers.get(0).getNextFireTime();
                  priority = triggers.get(0).getPriority();
              }

     sb.append("Name= "+ jobKey.getName() + " Group=" + jobKey.getGroup() + " NextFireTime=" + nextFireTime + " Priority=" + priority + " Paused=" + (isJobPaused(jobKey.getName())?"IS PAUSED":"NOT PAUSED") + " Triggers #=" + triggers.size() + "\r\n\r\n"); 
             }
         }

         sb.append("End Quartz Jobs\r\n\r\n");
  } catch (Exception e) {
   logger.debug("debugPrintJobs:" + e.getMessage());
  }

  return sb.toString();
 }

 private Boolean isJobPaused(String jobName) throws SchedulerException {
  Scheduler scheduler = this.getJobScheduler();
     JobKey jobKey = new JobKey(jobName);
     JobDetail jobDetail = scheduler.getJobDetail(jobKey);
     List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobDetail.getKey());
     for (Trigger trigger : triggers) {
         TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
         if (TriggerState.PAUSED.equals(triggerState)) {
             return true;
         }
     }
     return false;
 }

1 个答案:

答案 0 :(得分:1)

我还没有用它来解决任何问题,但以下界面可以帮到你。

当Quartz无法启动作业时,TriggerListener可能会检查失误。

JobListener可以检查已完成的成功和失败案例的作业。

http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-07.html