使用springboot構造quartz的rest api

給quartz對job、trigger的一些操做增長rest apiapi

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的分頁處理,因此當數據量的狀況下,查詢就比較麻煩。有待對原生的查詢進行擴展。app

相關文章
相關標籤/搜索