From b2b7b8e095c251e2022e89a780ab95ac5285e1bc Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 13 Jan 2022 21:00:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9C=BA=E6=99=AF=E6=89=A7=E8=A1=8C):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9C=BA=E6=99=AF=E6=89=A7=E8=A1=8C=E4=B8=AD?= =?UTF-8?q?=E6=AD=A5=E9=AA=A4=E8=B6=85=E6=97=B6=E5=88=A4=E6=96=AD=E7=9A=84?= =?UTF-8?q?=E8=A1=A8=E8=BE=BE=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化场景执行中步骤超时判断的表达式 --- .../api/service/ApiExecutionQueueService.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java b/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java index dbdba9e4e7..fba80ea0d6 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java @@ -224,17 +224,20 @@ public class ApiExecutionQueueService { public void timeOut() { final int SECOND_MILLIS = 1000; final int MINUTE_MILLIS = 60 * SECOND_MILLIS; - // 二十分钟前的超时报告 - final long now = System.currentTimeMillis() - (20 * MINUTE_MILLIS); + // 计算二十分钟前的超时报告 + final long timeBeforeTimeOutStemp = System.currentTimeMillis() - (20 * MINUTE_MILLIS); ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample(); - example.createCriteria().andCreateTimeLessThan(now); + example.createCriteria().andCreateTimeLessThan(timeBeforeTimeOutStemp); List queueDetails = executionQueueDetailMapper.selectByExample(example); if (CollectionUtils.isNotEmpty(queueDetails)) { queueDetails.forEach(item -> { if (StringUtils.equalsAnyIgnoreCase(item.getType(), ApiRunMode.SCENARIO.name(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) { ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(item.getReportId()); - if (report != null && StringUtils.equalsAnyIgnoreCase(report.getStatus(), TestPlanReportStatus.RUNNING.name()) && (System.currentTimeMillis() - report.getUpdateTime()) < now) { + if (report != null + && StringUtils.equalsAnyIgnoreCase(report.getStatus(), TestPlanReportStatus.RUNNING.name()) + && report.getUpdateTime() < timeBeforeTimeOutStemp) { + //场景报告最后一次更新时间于当前时间相比超过了20分钟,也就是20分钟没有步骤执行完成。这种情况下做超时处理 report.setStatus(ScenarioStatus.Timeout.name()); apiScenarioReportMapper.updateByPrimaryKeySelective(report); @@ -265,12 +268,13 @@ public class ApiExecutionQueueService { } ApiExecutionQueueExample queueDetailExample = new ApiExecutionQueueExample(); - queueDetailExample.createCriteria().andReportTypeEqualTo(RunModeConstants.SET_REPORT.toString()).andCreateTimeLessThan(now); + queueDetailExample.createCriteria().andReportTypeEqualTo(RunModeConstants.SET_REPORT.toString()).andCreateTimeLessThan(timeBeforeTimeOutStemp); List executionQueues = queueMapper.selectByExample(queueDetailExample); if (CollectionUtils.isNotEmpty(executionQueues)) { executionQueues.forEach(item -> { ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(item.getReportId()); - if (report != null && StringUtils.equalsAnyIgnoreCase(report.getStatus(), TestPlanReportStatus.RUNNING.name()) && (System.currentTimeMillis() - report.getUpdateTime()) < now) { + if (report != null && StringUtils.equalsAnyIgnoreCase(report.getStatus(), TestPlanReportStatus.RUNNING.name()) + && (report.getUpdateTime() < timeBeforeTimeOutStemp)) { report.setStatus(ScenarioStatus.Timeout.name()); apiScenarioReportMapper.updateByPrimaryKeySelective(report); }