给quartz对job、trigger的一些操作增加rest api

trigger

    @RequestMapping(value = "/trigger/keys",method = RequestMethod.GET)
    public Set<TriggerKey> getTriggerKeys(@RequestParam(required = false) String group) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            return scheduler.getTriggerKeys(GroupMatcher.anyTriggerGroup());
        }

        return scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(group));
    }

    @RequestMapping(value = "/trigger",method = RequestMethod.GET)
    public Trigger getTriggerDetail(@RequestParam(required = false) String group,
                                  @RequestParam String name) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            return scheduler.getTrigger(TriggerKey.triggerKey(name));
        }

        return scheduler.getTrigger(TriggerKey.triggerKey(name,group));
    }

    @RequestMapping(value = "/trigger/pause",method = RequestMethod.POST)
    public void pauseTrigger(@RequestParam(required = false) String group,
                                    @RequestParam String name) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            scheduler.pauseTrigger(TriggerKey.triggerKey(name));
        }

        scheduler.pauseTrigger(TriggerKey.triggerKey(name,group));
    }

    @RequestMapping(value = "/trigger/resume",method = RequestMethod.POST)
    public void resumeTrigger(@RequestParam(required = false) String group,
                             @RequestParam String name) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            scheduler.resumeTrigger(TriggerKey.triggerKey(name));
        }

        scheduler.resumeTrigger(TriggerKey.triggerKey(name,group));
    }

    @RequestMapping(value = "/trigger",method = RequestMethod.DELETE)
    public void deleteTrigger(@RequestParam(required = false) String group,
                              @RequestParam String name) throws SchedulerException {
        TriggerKey triggerKey = null;
        if(StringUtils.isBlank(group)){
            triggerKey = TriggerKey.triggerKey(name);
        }else{
            triggerKey = TriggerKey.triggerKey(name,group);
        }
        scheduler.pauseTrigger(triggerKey);
        scheduler.unscheduleJob(triggerKey); //only remove trigger
    }

job

@RequestMapping(value = "/job/keys",method = RequestMethod.GET)
    public Set<JobKey> getJobKeys(@RequestParam(required = false) String group) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            return scheduler.getJobKeys(GroupMatcher.anyJobGroup());
        }

        return scheduler.getJobKeys(GroupMatcher.jobGroupEquals(group));
    }

    @RequestMapping(value = "/job",method = RequestMethod.GET)
    public JobDetail getJobDetail(@RequestParam(required = false) String group,
                                            @RequestParam String name) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            return scheduler.getJobDetail(JobKey.jobKey(name));
        }

        return scheduler.getJobDetail(JobKey.jobKey(name,group));
    }

    @RequestMapping(value = "/job",method = RequestMethod.DELETE)
    public void deleteJob(@RequestParam String group,
                          @RequestParam String name) throws SchedulerException {
        scheduler.deleteJob(JobKey.jobKey(name, group));
    }

小结

基本的操作都可以使用rest来满足,但是原生的api没有对job以及trigger的分页处理,所以当数据量的情况下,查询就比较麻烦。有待对原生的查询进行扩展。


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...