首页 > 其他分享 >xxl-job如何停止某一个任务?

xxl-job如何停止某一个任务?

时间:2022-12-22 10:02:38浏览次数:41  
标签:removeJob quartz return String job triggerKey 停止 ReturnT xxl

停止,通过quartz调度器的unscheduleJob()方法,取消quartz的调度。

public ReturnT<String> stop(int id) {
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
String group = String.valueOf(xxlJobInfo.getJobGroup());
String name = String.valueOf(xxlJobInfo.getId());

try {
// bind quartz
boolean ret = XxlJobDynamicScheduler.removeJob(name, group);
return ret?ReturnT.SUCCESS:ReturnT.FAIL;
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
return ReturnT.FAIL;
}
}

public static boolean removeJob(String jobName, String jobGroup) throws SchedulerException {

TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);

if (scheduler.checkExists(triggerKey)) {
scheduler.unscheduleJob(triggerKey); // trigger + job
}

logger.info(">>>>>>>>>>> removeJob success, triggerKey:{}", triggerKey);
return true;
}

标签:removeJob,quartz,return,String,job,triggerKey,停止,ReturnT,xxl
From: https://blog.51cto.com/u_13488918/5962365

相关文章