From cec42ebde26a2602498c245b601d0fab024e926a Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 11 Jun 2025 19:06:09 +0800 Subject: [PATCH 1/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=AE=A1=E7=90=86=E9=A1=B5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E5=88=97=E6=98=BE=E7=A4=BA=E4=BD=9C=E4=B8=9A=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=B7=B2=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1441426846482432]定时作业管理页增加一列显示作业是否已加载 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1441426846482432 --- .../java/neatlogic/framework/scheduler/dto/JobVo.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/neatlogic/framework/scheduler/dto/JobVo.java b/src/main/java/neatlogic/framework/scheduler/dto/JobVo.java index d9abcbb08..3be89ea11 100644 --- a/src/main/java/neatlogic/framework/scheduler/dto/JobVo.java +++ b/src/main/java/neatlogic/framework/scheduler/dto/JobVo.java @@ -56,6 +56,9 @@ public class JobVo extends BasePageVo { @EntityField(name = "结束时间", type = ApiParamType.LONG) private Date endTime; + @EntityField(name = "是否已加载", + type = ApiParamType.INTEGER) + private Integer isLoad; private JobStatusVo jobStatus; @@ -181,4 +184,11 @@ public class JobVo extends BasePageVo { return 0; } + public Integer getIsLoad() { + return isLoad; + } + + public void setIsLoad(Integer isLoad) { + this.isLoad = isLoad; + } } -- Gitee From b969081e1e844d4d1542c9173fa2541648d3dd8a Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 11 Jun 2025 19:35:28 +0800 Subject: [PATCH 2/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=AE=A1=E7=90=86=E9=A1=B5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E5=88=97=E6=98=BE=E7=A4=BA=E4=BD=9C=E4=B8=9A=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=B7=B2=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1441426846482432]定时作业管理页增加一列显示作业是否已加载 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1441426846482432 --- .../framework/scheduler/core/JobBase.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/neatlogic/framework/scheduler/core/JobBase.java b/src/main/java/neatlogic/framework/scheduler/core/JobBase.java index f96d0fec7..96ab4a7b2 100644 --- a/src/main/java/neatlogic/framework/scheduler/core/JobBase.java +++ b/src/main/java/neatlogic/framework/scheduler/core/JobBase.java @@ -96,13 +96,14 @@ public abstract class JobBase implements IJob { // 如果锁的状态是running状态,证明其他节点已经在执行,直接返回 if (jobLockVo.getLock().equals(JobLockVo.RUNNING) && !jobLockVo.getServerId().equals(Config.SCHEDULE_SERVER_ID)) { jobLockVo = null; + } else { + // 修改锁状态 + jobLockVo.setServerId(Config.SCHEDULE_SERVER_ID); + jobLockVo.setLock(JobLockVo.RUNNING); + schedulerMapper.updateJobLock(jobLockVo); } - } - if (jobLockVo != null) { - // 修改锁状态 - jobLockVo.setServerId(Config.SCHEDULE_SERVER_ID); - jobLockVo.setLock(JobLockVo.RUNNING); - schedulerMapper.updateJobLock(jobLockVo); + } else { + logger.error("执行定时作业(jobName={0},jobGroup={1})时,`schedule_job_lock`表中没有对应数据"); } } finally { transactionUtil.commitTx(ts); @@ -196,8 +197,12 @@ public abstract class JobBase implements IJob { } Date currentFireTime = context.getFireTime();// 本次执行激活时间 JobStatusVo beforeJobStatusVo = schedulerMapper.getJobStatusByJobNameGroup(jobName, jobGroup); + if (beforeJobStatusVo == null) { + logger.error("执行定时作业(jobName={0},jobGroup={1})时,`schedule_job_status`表中没有对应数据"); + return; + } // 如果数据库中记录的下次激活时间在本次执行激活时间之后,则放弃执行业务逻辑 - if (beforeJobStatusVo == null || (beforeJobStatusVo.getNextFireTime() != null && beforeJobStatusVo.getNextFireTime().after(currentFireTime))) { + if (beforeJobStatusVo.getNextFireTime() != null && beforeJobStatusVo.getNextFireTime().after(currentFireTime)) { return; } -- Gitee From a9749dc0db0c9426872bb536bd3e7be1a6cebf3e Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 12 Jun 2025 01:46:28 +0800 Subject: [PATCH 3/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=AE=A1=E7=90=86=E9=A1=B5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E5=88=97=E6=98=BE=E7=A4=BA=E4=BD=9C=E4=B8=9A=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=B7=B2=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1441426846482432]定时作业管理页增加一列显示作业是否已加载 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1441426846482432 --- .../framework/scheduler/core/JobBase.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/neatlogic/framework/scheduler/core/JobBase.java b/src/main/java/neatlogic/framework/scheduler/core/JobBase.java index 96ab4a7b2..36fe15104 100644 --- a/src/main/java/neatlogic/framework/scheduler/core/JobBase.java +++ b/src/main/java/neatlogic/framework/scheduler/core/JobBase.java @@ -27,7 +27,6 @@ import neatlogic.framework.scheduler.annotation.Param; import neatlogic.framework.scheduler.annotation.Prop; import neatlogic.framework.scheduler.dao.mapper.SchedulerMapper; import neatlogic.framework.scheduler.dto.*; -import neatlogic.framework.scheduler.exception.ScheduleHandlerNotFoundException; import neatlogic.framework.scheduler.exception.ScheduleIllegalParameterException; import neatlogic.framework.scheduler.exception.ScheduleParamNotExistsException; import neatlogic.framework.transaction.util.TransactionUtil; @@ -42,13 +41,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.support.TransactionSynchronizationManager; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; /** @@ -103,7 +100,7 @@ public abstract class JobBase implements IJob { schedulerMapper.updateJobLock(jobLockVo); } } else { - logger.error("执行定时作业(jobName={0},jobGroup={1})时,`schedule_job_lock`表中没有对应数据"); + logger.error(String.format("执行定时作业(jobName=%s,jobGroup=%s)时,`schedule_job_lock`表中没有对应数据", jobName, jobGroup)); } } finally { transactionUtil.commitTx(ts); @@ -167,6 +164,10 @@ public abstract class JobBase implements IJob { @Override public final void execute(JobExecutionContext context) throws JobExecutionException { + if (TransactionSynchronizationManager.isSynchronizationActive()) { + logger.error(String.format("定时作业%s类的execute()方法不应该开始事务", this.getClassName())); + return; + } InputFromContext.init(InputFrom.CRON); Date fireTime = new Date(); JobDetail jobDetail = context.getJobDetail(); @@ -177,6 +178,7 @@ public abstract class JobBase implements IJob { String tenantUuid = jobObject.getTenantUuid(); //如果租户不存在则不执行该租户的作业 if (!TenantUtil.hasTenant(tenantUuid)) { + logger.error(String.format("执行定时作业(jobName=%s,jobGroup=%s)时,租户:%s不存在", jobName, jobGroup, tenantUuid)); return; } // 从job组名中获取租户uuid,切换到租户的数据源 @@ -186,19 +188,22 @@ public abstract class JobBase implements IJob { IJob jobHandler = SchedulerManager.getHandler(this.getClassName()); if (jobHandler == null) { schedulerManager.unloadJob(jobObject); - throw new ScheduleHandlerNotFoundException(jobObject.getJobHandler()); + logger.error(String.format("执行定时作业(jobName=%s,jobGroup=%s)时,定时作业组件:%s不存在", jobName, jobGroup, this.getClassName())); + return; +// throw new ScheduleHandlerNotFoundException(jobObject.getJobHandler()); } if (!jobHandler.isHealthy(jobObject)) { // not healthy 不能unloadJob 否则会删除作业状态和锁,导致正常接管的server也无法跑作业。 // 例如:A Server 修改cron 每天0点跑作业,B Server 修改cron每分钟跑。 当A Server 发现not healthy 则会unload 并删除status,lock。后续判断会导致B Server 也不会再跑作业。 // 应该有jobHandler来自行判断是否需要unloadJob //schedulerManager.unloadJob(jobObject); + logger.error(String.format("执行定时作业(jobName=%s,jobGroup=%s)时,isHealthy()方法检查出作业不正常", jobName, jobGroup)); return; } Date currentFireTime = context.getFireTime();// 本次执行激活时间 JobStatusVo beforeJobStatusVo = schedulerMapper.getJobStatusByJobNameGroup(jobName, jobGroup); if (beforeJobStatusVo == null) { - logger.error("执行定时作业(jobName={0},jobGroup={1})时,`schedule_job_status`表中没有对应数据"); + logger.error(String.format("执行定时作业(jobName=%s,jobGroup=%s)时,`schedule_job_status`表中没有对应数据", jobName, jobGroup)); return; } // 如果数据库中记录的下次激活时间在本次执行激活时间之后,则放弃执行业务逻辑 @@ -214,7 +219,7 @@ public abstract class JobBase implements IJob { } JobStatusVo oldJobStatusVo = schedulerMapper.getJobStatusByJobNameGroup(jobName, jobGroup); // 前后执行次数不一致,证明已经执行过,直接退出 - if (beforeJobStatusVo.getExecCount().intValue() != oldJobStatusVo.getExecCount().intValue()) { + if (!Objects.equals(beforeJobStatusVo.getExecCount(), oldJobStatusVo.getExecCount())) { return; } try { -- Gitee From b0a1cd5a771174c839298e153c5c8d71a9842480 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 12 Jun 2025 07:44:01 +0800 Subject: [PATCH 4/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=AE=A1=E7=90=86=E9=A1=B5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E5=88=97=E6=98=BE=E7=A4=BA=E4=BD=9C=E4=B8=9A=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=B7=B2=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1441426846482432]定时作业管理页增加一列显示作业是否已加载 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1441426846482432 --- .../java/neatlogic/framework/scheduler/core/JobBase.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/neatlogic/framework/scheduler/core/JobBase.java b/src/main/java/neatlogic/framework/scheduler/core/JobBase.java index 36fe15104..78733f739 100644 --- a/src/main/java/neatlogic/framework/scheduler/core/JobBase.java +++ b/src/main/java/neatlogic/framework/scheduler/core/JobBase.java @@ -258,7 +258,11 @@ public abstract class JobBase implements IJob { schedulerMapper.updateJobAudit(auditVo); } } else { - jobHandler.executeInternal(context, jobObject); + try { + jobHandler.executeInternal(context, jobObject); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } } /* 异步模式,如果事务hold住时间太长,可以考虑使用异步模式,但作业的执行时间需要手动处理 -- Gitee