From fa5e502e807413820daebd8ecff5706b171b16b1 Mon Sep 17 00:00:00 2001 From: jet Date: Sun, 26 May 2024 17:40:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(job-admin)=20=E4=BC=98=E5=8C=96=E6=80=A7?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E5=87=8F=E5=B0=91=E6=97=A5=E5=BF=97=E7=9A=84?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xxl/job/admin/core/thread/JobCompleteHelper.java | 4 +++- .../src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java | 2 +- .../src/main/resources/mybatis-mapper/XxlJobLogMapper.xml | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobCompleteHelper.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobCompleteHelper.java index 5698926a26..e9d936b7d8 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobCompleteHelper.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobCompleteHelper.java @@ -76,7 +76,9 @@ public void run() { try { // 任务结果丢失处理:调度记录停留在 "运行中" 状态超过10min,且对应执行器心跳注册失败不在线,则将本地调度主动标记失败; Date losedTime = DateUtil.addMinutes(new Date(), -10); - List losedJobIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findLostJobIds(losedTime); + Date fromTime = DateUtil.addMinutes(new Date(), -20); + //缩小时间范围,减少查询范围,挑选从20分钟前到10分钟前的任务来查询,因为每间隔1分钟已经检查过一次。 + List losedJobIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findLostJobIds(losedTime, fromTime); if (losedJobIds!=null && losedJobIds.size()>0) { for (Long logId: losedJobIds) { diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java index 62fa3b4f90..ecdaf4a1f4 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java @@ -57,6 +57,6 @@ public int updateAlarmStatus(@Param("logId") long logId, @Param("oldAlarmStatus") int oldAlarmStatus, @Param("newAlarmStatus") int newAlarmStatus); - public List findLostJobIds(@Param("losedTime") Date losedTime); + public List findLostJobIds(@Param("losedTime") Date losedTime, @Param("fromTime") Date fromTime); } diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml index 4155f17982..04c59daabc 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml @@ -256,6 +256,7 @@ t.trigger_code = 200 AND t.handle_code = 0 AND t.trigger_time #{losedTime} + AND t.trigger_time = ]]> #{fromTime} AND t2.id IS NULL;