任务Cron更新逻辑优化,改为rescheduleJob,同时防止cron重复设置;

pull/3/head
xueli.xue 8 years ago
parent 54d92de752
commit 25cf93fdc2

@ -847,6 +847,9 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 5、执行参数编辑时丢失问题修复 - 5、执行参数编辑时丢失问题修复
- 6、新增任务测试Demo方便在开发时进行任务逻辑测试 - 6、新增任务测试Demo方便在开发时进行任务逻辑测试
#### 6.16 版本 V1.8.0 特性[Coding]
- 1、任务Cron更新逻辑优化改为rescheduleJob同时防止cron重复设置
#### TODO LIST #### TODO LIST
- 1、任务权限管理执行器为粒度分配权限核心操作校验权限 - 1、任务权限管理执行器为粒度分配权限核心操作校验权限
- 2、任务分片一个任务被拆分成N个独立的任务单元然后由分布式部署的执行器分别执行某一个或几个分片单元 - 2、任务分片一个任务被拆分成N个独立的任务单元然后由分布式部署的执行器分别执行某一个或几个分片单元

@ -193,15 +193,28 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
// TriggerKey : name + group // TriggerKey : name + group
TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup); TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
JobKey jobKey = new JobKey(jobName, jobGroup); CronTrigger oldTrigger = (CronTrigger) scheduler.getTrigger(triggerKey);
if (oldTrigger != null) {
// avoid repeat
String oldCron = oldTrigger.getCronExpression();
if (oldCron.equals(cronExpression)){
return true;
}
// CronTrigger : TriggerKey + cronExpression // CronTrigger : TriggerKey + cronExpression
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing(); CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing();
CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build(); oldTrigger = oldTrigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();
//scheduler.rescheduleJob(triggerKey, cronTrigger); // rescheduleJob
scheduler.rescheduleJob(triggerKey, oldTrigger);
} else {
// CronTrigger : TriggerKey + cronExpression
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing();
CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();
// JobDetail-JobDataMap fresh // JobDetail-JobDataMap fresh
JobKey jobKey = new JobKey(jobName, jobGroup);
JobDetail jobDetail = scheduler.getJobDetail(jobKey); JobDetail jobDetail = scheduler.getJobDetail(jobKey);
/*JobDataMap jobDataMap = jobDetail.getJobDataMap(); /*JobDataMap jobDataMap = jobDetail.getJobDataMap();
jobDataMap.clear(); jobDataMap.clear();
@ -212,6 +225,8 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
triggerSet.add(cronTrigger); triggerSet.add(cronTrigger);
scheduler.scheduleJob(jobDetail, triggerSet, true); scheduler.scheduleJob(jobDetail, triggerSet, true);
}
logger.info(">>>>>>>>>>> resumeJob success, JobGroup:{}, JobName:{}", jobGroup, jobName); logger.info(">>>>>>>>>>> resumeJob success, JobGroup:{}, JobName:{}", jobGroup, jobName);
return true; return true;
} }

Loading…
Cancel
Save