序
给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的分页处理,所以当数据量的情况下,查询就比较麻烦。有待对原生的查询进行扩展。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。