提交 5b280137 authored 作者: xuxueli's avatar xuxueli

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

上级 90eba382
...@@ -1519,6 +1519,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 ...@@ -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 { ...@@ -78,12 +78,15 @@ public class JobScheduleHelper {
// 过期超5s:本地忽略,当前时间开始计算下次触发时间 // 过期超5s:本地忽略,当前时间开始计算下次触发时间
// fresh next // fresh next
Date nextValidTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date());
if (nextValidTime != null) {
jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime()); jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime());
jobInfo.setTriggerNextTime( jobInfo.setTriggerNextTime(nextValidTime.getTime());
new CronExpression(jobInfo.getJobCron()) } else {
.getNextValidTimeAfter(new Date()) jobInfo.setTriggerStatus(0);
.getTime() 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 { ...@@ -110,12 +113,15 @@ public class JobScheduleHelper {
pushTimeRing(ringSecond, jobInfo.getId()); pushTimeRing(ringSecond, jobInfo.getId());
// 3、fresh next // 3、fresh next
Date nextValidTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date(jobInfo.getTriggerNextTime()));
if (nextValidTime != null) {
jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime()); jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime());
jobInfo.setTriggerNextTime( jobInfo.setTriggerNextTime(nextValidTime.getTime());
new CronExpression(jobInfo.getJobCron()) } else {
.getNextValidTimeAfter(new Date(jobInfo.getTriggerNextTime())) jobInfo.setTriggerStatus(0);
.getTime() jobInfo.setTriggerLastTime(0);
); jobInfo.setTriggerNextTime(0);
}
} }
...@@ -129,12 +135,15 @@ public class JobScheduleHelper { ...@@ -129,12 +135,15 @@ public class JobScheduleHelper {
pushTimeRing(ringSecond, jobInfo.getId()); pushTimeRing(ringSecond, jobInfo.getId());
// 3、fresh next // 3、fresh next
Date nextValidTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date(jobInfo.getTriggerNextTime()));
if (nextValidTime != null) {
jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime()); jobInfo.setTriggerLastTime(jobInfo.getTriggerNextTime());
jobInfo.setTriggerNextTime( jobInfo.setTriggerNextTime(nextValidTime.getTime());
new CronExpression(jobInfo.getJobCron()) } else {
.getNextValidTimeAfter(new Date(jobInfo.getTriggerNextTime())) jobInfo.setTriggerStatus(0);
.getTime() jobInfo.setTriggerLastTime(0);
); jobInfo.setTriggerNextTime(0);
}
} }
......
...@@ -194,7 +194,11 @@ public class XxlJobServiceImpl implements XxlJobService { ...@@ -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 { ...@@ -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=任务描述 ...@@ -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 ...@@ -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 @@ ...@@ -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>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论