From 34282715ce85a732771ba66af7b60007fcc6af5c Mon Sep 17 00:00:00 2001 From: yangsanity <471419897@qq.com> Date: Mon, 5 Jul 2021 22:30:53 +0800 Subject: [PATCH] script_history add submit_time and refactor execTimeout --- script/big-whale.sql | 3 ++- .../java/com/meiyou/bigwhale/entity/ScriptHistory.java | 1 + .../com/meiyou/bigwhale/job/ScheduleSubmitJob.java | 1 + .../bigwhale/service/ScriptHistoryServiceImpl.java | 10 ++-------- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/script/big-whale.sql b/script/big-whale.sql index 24e0beb..d9ac429 100644 --- a/script/big-whale.sql +++ b/script/big-whale.sql @@ -459,7 +459,8 @@ ALTER TABLE `script_history` CHANGE COLUMN `state` `state` VARCHAR(255) NOT NULL COLLATE 'utf8_general_ci' AFTER `content`, CHANGE COLUMN `steps` `steps` VARCHAR(255) NOT NULL COLLATE 'utf8_general_ci' AFTER `state`, ADD COLUMN `job_params` VARCHAR(255) NULL DEFAULT NULL AFTER `finish_time`, - DROP COLUMN `schedule_snapshot_id`; + DROP COLUMN `schedule_snapshot_id`, + ADD COLUMN `submit_time` DATETIME NULL DEFAULT NULL AFTER `create_by`; DROP TABLE `schedule_snapshot`; diff --git a/src/main/java/com/meiyou/bigwhale/entity/ScriptHistory.java b/src/main/java/com/meiyou/bigwhale/entity/ScriptHistory.java index 2b2a8ad..c9a3f84 100644 --- a/src/main/java/com/meiyou/bigwhale/entity/ScriptHistory.java +++ b/src/main/java/com/meiyou/bigwhale/entity/ScriptHistory.java @@ -53,6 +53,7 @@ public class ScriptHistory { private String errors; private Date createTime; private Integer createBy; + private Date submitTime; private Date startTime; private Date finishTime; diff --git a/src/main/java/com/meiyou/bigwhale/job/ScheduleSubmitJob.java b/src/main/java/com/meiyou/bigwhale/job/ScheduleSubmitJob.java index 2dc57ff..4e1a5cd 100644 --- a/src/main/java/com/meiyou/bigwhale/job/ScheduleSubmitJob.java +++ b/src/main/java/com/meiyou/bigwhale/job/ScheduleSubmitJob.java @@ -47,6 +47,7 @@ public void execute(JobExecutionContext jobExecutionContext) { } } scriptHistory.updateState(state); + scriptHistory.setSubmitTime(new Date()); if (Constant.JobState.INITED.equals(state)) { scriptHistory = scriptHistoryService.save(scriptHistory); ScriptHistoryShellRunnerJob.build(scriptHistory); diff --git a/src/main/java/com/meiyou/bigwhale/service/ScriptHistoryServiceImpl.java b/src/main/java/com/meiyou/bigwhale/service/ScriptHistoryServiceImpl.java index 10252e3..9f14ec6 100644 --- a/src/main/java/com/meiyou/bigwhale/service/ScriptHistoryServiceImpl.java +++ b/src/main/java/com/meiyou/bigwhale/service/ScriptHistoryServiceImpl.java @@ -29,14 +29,8 @@ public void missingScheduling(ScriptHistory scriptHistory) { public boolean execTimeout(ScriptHistory scriptHistory) { Date ago = DateUtils.addMinutes(new Date(), -scriptHistory.getTimeout()); // 执行超时 - Date time; - if (scriptHistory.getStartTime() != null) { - time = scriptHistory.getStartTime(); - } else if (scriptHistory.getScheduleOperateTime() != null) { - time = scriptHistory.getScheduleOperateTime(); - } else { - time = scriptHistory.getCreateTime(); - } + // submitTime is definitely not null here + Date time = scriptHistory.getSubmitTime(); return time.compareTo(ago) <= 0; }