diff --git a/lts-core/src/main/java/com/github/ltsopensource/queue/support/NonRelyJobUtils.java b/lts-core/src/main/java/com/github/ltsopensource/queue/support/NonRelyJobUtils.java index ac2ad24ad..6eef1496b 100644 --- a/lts-core/src/main/java/com/github/ltsopensource/queue/support/NonRelyJobUtils.java +++ b/lts-core/src/main/java/com/github/ltsopensource/queue/support/NonRelyJobUtils.java @@ -81,10 +81,13 @@ public static void addRepeatJobForInterval( } // 计算出应该重复的次数 int repeatedCount = Long.valueOf((lastGenerateTime.getTime() - firstTriggerTime) / jobPo.getRepeatInterval()).intValue(); + if (repeatedCount <= 0) { + repeatedCount = 1; //repeatedCount从1开始 + } boolean stop = false; while (!stop) { - Long nextTriggerTime = firstTriggerTime + repeatedCount * repeatInterval; + Long nextTriggerTime = firstTriggerTime + (repeatedCount - 1) * repeatInterval; //第一次执行时间点应该是firstTriggerTime if (nextTriggerTime <= endTime && (repeatCount == -1 || repeatedCount <= repeatCount)) { diff --git a/lts-jobtracker/src/main/java/com/github/ltsopensource/jobtracker/complete/JobFinishHandler.java b/lts-jobtracker/src/main/java/com/github/ltsopensource/jobtracker/complete/JobFinishHandler.java index 30dc29d67..d400392b2 100644 --- a/lts-jobtracker/src/main/java/com/github/ltsopensource/jobtracker/complete/JobFinishHandler.java +++ b/lts-jobtracker/src/main/java/com/github/ltsopensource/jobtracker/complete/JobFinishHandler.java @@ -117,7 +117,7 @@ private void finishNoReplyPrevRepeatJob(JobMeta jobMeta, boolean isRetryForThisT // 可能任务队列中改条记录被删除了 return; } - if (jobPo.getRepeatCount() != -1 && jobPo.getRepeatedCount() >= jobPo.getRepeatCount()) { + if (jobPo.getRepeatCount() != -1 && (jobPo.getRepeatedCount() + 1) >= jobPo.getRepeatCount()) { //最后一次执行时 repeatedCount+1=repeatCount // 已经重试完成, 那么删除, 这里可以不用check可执行队列是否还有,因为这里依赖的是计数 appContext.getRepeatJobQueue().remove(jobPo.getJobId()); jobRemoveLog(jobPo, "Repeat"); @@ -137,7 +137,7 @@ private void finishRepeatJob(String jobId, boolean isRetryForThisTime) { // 可能任务队列中改条记录被删除了 return; } - if (jobPo.getRepeatCount() != -1 && jobPo.getRepeatedCount() >= jobPo.getRepeatCount()) { + if (jobPo.getRepeatCount() != -1 && (jobPo.getRepeatedCount() + 1) >= jobPo.getRepeatCount()) { //最后一次执行时 repeatedCount+1=repeatCount // 已经重试完成, 那么删除 appContext.getRepeatJobQueue().remove(jobId); jobRemoveLog(jobPo, "Repeat"); @@ -156,7 +156,7 @@ private void finishRepeatJob(String jobId, boolean isRetryForThisTime) { } long nexTriggerTime = JobUtils.getRepeatNextTriggerTime(jobPo); try { - jobPo.setRepeatedCount(repeatedCount); + jobPo.setRepeatedCount(repeatedCount + 1); //再生成可执行job时,从RepeatJobQueue更新后的repeatedCount再加1 jobPo.setTaskTrackerIdentity(null); jobPo.setIsRunning(false); jobPo.setTriggerTime(nexTriggerTime);