refactor: 定时任务区分group

This commit is contained in:
CaptainB 2024-04-07 22:18:28 +08:00 committed by 刘瑞斌
parent f8cd30f6d4
commit f98260a2eb
1 changed files with 5 additions and 5 deletions

View File

@ -29,12 +29,12 @@ public class BaseScheduleService {
try { try {
if (schedule.getEnable()) { if (schedule.getEnable()) {
LogUtils.info("初始化任务:" + JSON.toJSONString(schedule)); LogUtils.info("初始化任务:" + JSON.toJSONString(schedule));
scheduleManager.addOrUpdateCronJob(new JobKey(schedule.getKey()), scheduleManager.addOrUpdateCronJob(new JobKey(schedule.getKey(), schedule.getJob()),
new TriggerKey(schedule.getKey()), Class.forName(schedule.getJob()), schedule.getValue(), new TriggerKey(schedule.getKey(),schedule.getJob()), Class.forName(schedule.getJob()), schedule.getValue(),
scheduleManager.getDefaultJobDataMap(schedule, schedule.getValue(), schedule.getCreateUser())); scheduleManager.getDefaultJobDataMap(schedule, schedule.getValue(), schedule.getCreateUser()));
} else { } else {
// 删除关闭的job // 删除关闭的job
removeJob(schedule.getKey()); removeJob(schedule);
} }
} catch (Exception e) { } catch (Exception e) {
LogUtils.error("初始化任务失败", e); LogUtils.error("初始化任务失败", e);
@ -49,7 +49,7 @@ public class BaseScheduleService {
return scheduleMapper.selectByExample(example); return scheduleMapper.selectByExample(example);
} }
private void removeJob(String key) { private void removeJob(Schedule schedule) {
scheduleManager.removeJob(new JobKey(key), new TriggerKey(key)); scheduleManager.removeJob(new JobKey(schedule.getKey(), schedule.getJob()), new TriggerKey(schedule.getKey(), schedule.getJob()));
} }
} }