Quartz查询所有的定时任务

Quartz查询所有的定时任务,第1张

Quartz查询所有的定时任务
import com.collect.engine.vo.QuartzJobsVO;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.quartz.impl.matchers.GroupMatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;



@Slf4j
@RestController
@RequestMapping("/quartz")
public class ManageQuartzJobs {

    @Autowired
    private Scheduler scheduler;

    @GetMapping("/getAllJobs")
    public List getAllJob(){
        GroupMatcher matcher = GroupMatcher.anyJobGroup();
        Set jobKeys = null;
        List jobList = new ArrayList();
        try {
            jobKeys = scheduler.getJobKeys(matcher);
            for (JobKey jobKey : jobKeys) {
                List triggers = scheduler.getTriggersOfJob(jobKey);
                for (Trigger trigger : triggers) {
                    QuartzJobsVO job = new QuartzJobsVO();
                    job.setJobDetailName(jobKey.getName());
                    job.setGroupName(jobKey.getGroup());
                    job.setJobCronexpression("触发器:" + trigger.getKey());
                    Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
                    job.setStatus(triggerState.name());
                    if (trigger instanceof CronTrigger) {
                        CronTrigger cronTrigger = (CronTrigger) trigger;
                        String cronexpression = cronTrigger.getCronexpression();
                        job.setJobCronexpression(cronexpression);
                    }
                    jobList.add(job);
                }
            }

        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        return jobList;

    }
}

 返回值如下

[
    {
        "jobDetailName": "JobDetail-17",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-17",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-15",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-15",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-11",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-11",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-33",
        "jobCronexpression": "/30 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-33",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-13",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-13",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-35",
        "jobCronexpression": "/30 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-35",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-31",
        "jobCronexpression": "/30 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-31",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-19",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-19",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-26",
        "jobCronexpression": "/30 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-26",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-28",
        "jobCronexpression": "/10 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-28",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-22",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-22",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-24",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-24",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-20",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-20",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-5",
        "jobCronexpression": "/15 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-5",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-9",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-9",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-14",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-14",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-16",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-16",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-10",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-10",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-32",
        "jobCronexpression": "/30 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-32",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-12",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-12",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-34",
        "jobCronexpression": "/30 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-34",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-30",
        "jobCronexpression": "/12 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-30",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-18",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-18",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-25",
        "jobCronexpression": "/30 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-25",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-23",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-23",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-29",
        "jobCronexpression": "/13 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-29",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-21",
        "jobCronexpression": "1 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-21",
        "status": "NORMAL"
    },
    {
        "jobDetailName": "JobDetail-27",
        "jobCronexpression": "/10 * * * * ?",
        "groupName": "3189f717470a4b2c85dc334e3a5b3a16-27",
        "status": "NORMAL"
    }
]

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5438400.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存