调度组件优化:针对永远不会触发的Cron禁止配置和启动;任务Cron最后一次触发后再也不会触发时,比如一次性任务,主动停止相关任务;

pull/10/head
xuxueli 6 years ago
parent 90eba3827d
commit 5b280137fb

@ -1519,6 +1519,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 8、[ING]任务、执行器数据全量本地缓存;新增消息表广播通知; - 8、[ING]任务、执行器数据全量本地缓存;新增消息表广播通知;
- 9、[ING]任务触发组件优化常规1s预加载一次轮空时主动休眠4s - 9、[ING]任务触发组件优化常规1s预加载一次轮空时主动休眠4s
- 10、注册监控线程优化降低死锁几率 - 10、注册监控线程优化降低死锁几率
- 11、调度组件优化针对永远不会触发的Cron禁止配置和启动任务Cron最后一次触发后再也不会触发时比如一次性任务主动停止相关任务
### TODO LIST ### TODO LIST

@ -78,12 +78,15 @@ public class JobScheduleHelper {
// 过期超5s本地忽略当前时间开始计算下次触发时间 // 过期超5s本地忽略当前时间开始计算下次触发时间
// fresh next // fresh next
jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime()); Date nextValidTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date());
jobInfo.setTriggerNextTime( if (nextValidTime != null) {
new CronExpression(jobInfo.getJobCron()) jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime());
.getNextValidTimeAfter(new Date()) jobInfo.setTriggerNextTime(nextValidTime.getTime());
.getTime() } else {
); jobInfo.setTriggerStatus(0);
jobInfo.setTriggerLastTime(0);
jobInfo.setTriggerNextTime(0);
}
} else if (nowTime > jobInfo.getTriggerNextTime()) { } else if (nowTime > jobInfo.getTriggerNextTime()) {
// 过期5s内 :立即触发一次,当前时间开始计算下次触发时间; // 过期5s内 :立即触发一次,当前时间开始计算下次触发时间;
@ -110,12 +113,15 @@ public class JobScheduleHelper {
pushTimeRing(ringSecond, jobInfo.getId()); pushTimeRing(ringSecond, jobInfo.getId());
// 3、fresh next // 3、fresh next
jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime()); Date nextValidTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date(jobInfo.getTriggerNextTime()));
jobInfo.setTriggerNextTime( if (nextValidTime != null) {
new CronExpression(jobInfo.getJobCron()) jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime());
.getNextValidTimeAfter(new Date(jobInfo.getTriggerNextTime())) jobInfo.setTriggerNextTime(nextValidTime.getTime());
.getTime() } else {
); jobInfo.setTriggerStatus(0);
jobInfo.setTriggerLastTime(0);
jobInfo.setTriggerNextTime(0);
}
} }
@ -129,12 +135,15 @@ public class JobScheduleHelper {
pushTimeRing(ringSecond, jobInfo.getId()); pushTimeRing(ringSecond, jobInfo.getId());
// 3、fresh next // 3、fresh next
jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime()); Date nextValidTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date(jobInfo.getTriggerNextTime()));
jobInfo.setTriggerNextTime( if (nextValidTime != null) {
new CronExpression(jobInfo.getJobCron()) jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime());
.getNextValidTimeAfter(new Date(jobInfo.getTriggerNextTime())) jobInfo.setTriggerNextTime(nextValidTime.getTime());
.getTime() } else {
); jobInfo.setTriggerStatus(0);
jobInfo.setTriggerLastTime(0);
jobInfo.setTriggerNextTime(0);
}
} }

@ -194,7 +194,11 @@ public class XxlJobServiceImpl implements XxlJobService {
long nextTriggerTime = exists_jobInfo.getTriggerNextTime(); long nextTriggerTime = exists_jobInfo.getTriggerNextTime();
if (exists_jobInfo.getTriggerStatus() == 1 && !jobInfo.getJobCron().equals(exists_jobInfo.getJobCron()) ) { if (exists_jobInfo.getTriggerStatus() == 1 && !jobInfo.getJobCron().equals(exists_jobInfo.getJobCron()) ) {
try { try {
nextTriggerTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS)).getTime(); Date nextValidTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS));
if (nextValidTime == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_never_fire"));
}
nextTriggerTime = nextValidTime.getTime();
} catch (ParseException e) { } catch (ParseException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage()); return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage());
@ -240,7 +244,11 @@ public class XxlJobServiceImpl implements XxlJobService {
// next trigger time (5s后生效避开预读周期) // next trigger time (5s后生效避开预读周期)
long nextTriggerTime = 0; long nextTriggerTime = 0;
try { try {
nextTriggerTime = new CronExpression(xxlJobInfo.getJobCron()).getNextValidTimeAfter(new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS)).getTime(); Date nextValidTime = new CronExpression(xxlJobInfo.getJobCron()).getNextValidTimeAfter(new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS));
if (nextValidTime == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_never_fire"));
}
nextTriggerTime = nextValidTime.getTime();
} catch (ParseException e) { } catch (ParseException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage()); return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage());

@ -109,6 +109,7 @@ jobinfo_field_jobdesc=任务描述
jobinfo_field_gluetype=运行模式 jobinfo_field_gluetype=运行模式
jobinfo_field_executorparam=任务参数 jobinfo_field_executorparam=任务参数
jobinfo_field_cron_unvalid=Cron格式非法 jobinfo_field_cron_unvalid=Cron格式非法
jobinfo_field_cron_never_fire=Cron非法永远不会触发
jobinfo_field_author=负责人 jobinfo_field_author=负责人
jobinfo_field_timeout=任务超时时间 jobinfo_field_timeout=任务超时时间
jobinfo_field_alarmemail=报警邮件 jobinfo_field_alarmemail=报警邮件

@ -110,6 +110,7 @@ jobinfo_field_timeout=Job timeout period
jobinfo_field_gluetype=GLUE Type jobinfo_field_gluetype=GLUE Type
jobinfo_field_executorparam=Param jobinfo_field_executorparam=Param
jobinfo_field_cron_unvalid=The Cron is illegal jobinfo_field_cron_unvalid=The Cron is illegal
jobinfo_field_cron_never_fire=The Cron will never fire
jobinfo_field_author=Author jobinfo_field_author=Author
jobinfo_field_alarmemail=Alarm email jobinfo_field_alarmemail=Alarm email
jobinfo_field_alarmemail_placeholder=Please enter alarm mail, if there are more than one comma separated jobinfo_field_alarmemail_placeholder=Please enter alarm mail, if there are more than one comma separated

@ -219,7 +219,8 @@
UPDATE xxl_job_info UPDATE xxl_job_info
SET SET
trigger_last_time = #{triggerLastTime}, trigger_last_time = #{triggerLastTime},
trigger_next_time = #{triggerNextTime} trigger_next_time = #{triggerNextTime},
trigger_status = #{triggerStatus}
WHERE id = #{id} WHERE id = #{id}
</update> </update>

Loading…
Cancel
Save