From 2b10aa95cb5d943b143769422bd4f620079b4fc1 Mon Sep 17 00:00:00 2001 From: lusong <404828407@qq.com> Date: Thu, 27 Jul 2017 14:36:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3repeat=20job=E4=B8=A4?= =?UTF-8?q?=E4=B8=AAbug=EF=BC=9Ajob=E5=A4=9A=E6=89=A7=E8=A1=8C=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=EF=BC=8C=E4=B8=8D=E6=8C=89=E7=85=A7job=E7=9A=84?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E5=88=9D=E5=A7=8B=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E3=80=82=20=20repeatedCount=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E9=87=8D=E5=A4=8D=E7=9A=84=E6=AC=A1=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BB=8E1=E5=BC=80=E5=A7=8B=EF=BC=8C=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E5=80=BCrepeatCount=EF=BC=9BrepeatCount=E5=8F=AF=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=AC=A1=E6=95=B0=EF=BC=8C=E4=BB=8E0=E5=BC=80?= =?UTF-8?q?=E5=A7=8B=E3=80=82=20=20=E5=81=87=E5=A6=82=E5=8F=AF=E6=89=A7?= =?UTF-8?q?=E8=A1=8Cjob=E5=88=97=E8=A1=A8=E9=87=8C=E7=9A=84repeatedCount?= =?UTF-8?q?=E5=81=87=E5=A6=82=E4=B8=BA2=EF=BC=8C=E9=82=A3=E4=B9=88?= =?UTF-8?q?=E6=AD=A4=E6=97=B6RepeatJobQueue=E9=87=8C=E9=9D=A2=E7=9A=84repe?= =?UTF-8?q?atedCount=E5=80=BC=E5=BA=94=E8=AF=A5=E4=B8=BA1=E3=80=82?= =?UTF-8?q?=E5=BD=93=E8=BF=99=E4=B8=AA=E5=8F=AF=E6=89=A7=E8=A1=8Cjob?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=AE=8C=E5=90=8E=EF=BC=8CRepeatJobQueue?= =?UTF-8?q?=E9=87=8C=E9=9D=A2=E7=9A=84repeatedCount=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=B8=BA2=EF=BC=8C=E5=86=8D=E6=AC=A1=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84=E5=8F=AF=E6=89=A7=E8=A1=8Crepeat=20job=E9=87=8C?= =?UTF-8?q?=E7=9A=84repeatedCount=E5=BA=94=E8=AF=A5=E4=B8=BA3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/ltsopensource/queue/support/NonRelyJobUtils.java | 5 ++++- .../ltsopensource/jobtracker/complete/JobFinishHandler.java | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) 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);