From 1d9c4b2af75de87927bda351c52c2cdfae982dbd Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Thu, 24 Oct 2024 11:36:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=89=A7=E8=A1=8C=E5=A4=B1=E8=B4=A5=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=EF=BC=8C=E6=B2=A1=E6=9C=89=E6=9B=B4=E6=96=B0=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1047873 --user=陈建星 【任务中心】-批量执行场景,执行方式为串行+失败停止,批量执行任务不会自动停止,失败停止的场景处于等待排队状态 https://www.tapd.cn/55049933/s/1596875 --- .../api/listener/MessageListener.java | 8 +++++++- .../api/service/ApiBatchRunBaseService.java | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java b/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java index 2935ae0c71..7bb56db022 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java @@ -3,6 +3,7 @@ package io.metersphere.api.listener; import io.metersphere.api.invoker.ApiExecuteCallbackServiceInvoker; import io.metersphere.api.mapper.ApiReportMapper; import io.metersphere.api.mapper.ApiScenarioReportMapper; +import io.metersphere.api.service.ApiBatchRunBaseService; import io.metersphere.api.service.ApiReportSendNoticeService; import io.metersphere.api.service.definition.ApiTestCaseBatchRunService; import io.metersphere.api.service.queue.ApiExecutionQueueService; @@ -30,10 +31,11 @@ public class MessageListener { public static final String MESSAGE_CONSUME_ID = "MS-API-MESSAGE-CONSUME"; @Resource private ApiReportSendNoticeService apiReportSendNoticeService; - @Resource private ApiExecutionQueueService apiExecutionQueueService; @Resource + private ApiBatchRunBaseService apiBatchRunBaseService; + @Resource private ApiTestCaseBatchRunService apiTestCaseBatchRunService; @Resource private ApiScenarioBatchRunService apiScenarioBatchRunService; @@ -118,6 +120,10 @@ public class MessageListener { } if (isStopOnFailure(dto)) { ApiExecuteResourceType resourceType = EnumValidator.validateEnum(ApiExecuteResourceType.class, queue.getResourceType()); + if (resourceType != ApiExecuteResourceType.PLAN_RUN_API_SCENARIO && resourceType != ApiExecuteResourceType.PLAN_RUN_API_CASE) { + // 失败停止,更新任务状态 + apiBatchRunBaseService.updateTaskCompletedStatus(queue.getTaskId(), ResultStatus.ERROR.name()); + } // 补充集成报告 updateStopOnFailureIntegratedReport(dto, queue, resourceType); // 如果是失败停止,清空队列,不继续执行 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java index e5a0091e7c..ec5f557856 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java @@ -210,6 +210,10 @@ public class ApiBatchRunBaseService { } public void updateTaskCompletedStatus(String taskId) { + updateTaskCompletedStatus(taskId, null); + } + + public void updateTaskCompletedStatus(String taskId, String result) { // 删除执行缓存 removeRunningTaskCache(taskId); ExecTask originExecTask = execTaskMapper.selectByPrimaryKey(taskId); @@ -220,12 +224,16 @@ public class ApiBatchRunBaseService { execTask.setEndTime(System.currentTimeMillis()); execTask.setId(taskId); execTask.setStatus(ExecStatus.COMPLETED.name()); - if (extExecTaskItemMapper.hasErrorItem(taskId)) { - execTask.setResult(ResultStatus.ERROR.name()); - } else if (extExecTaskItemMapper.hasFakeErrorItem(taskId)) { - execTask.setResult(ResultStatus.FAKE_ERROR.name()); + if (StringUtils.isNotBlank(result)) { + execTask.setResult(result); } else { - execTask.setResult(ResultStatus.SUCCESS.name()); + if (extExecTaskItemMapper.hasErrorItem(taskId)) { + execTask.setResult(ResultStatus.ERROR.name()); + } else if (extExecTaskItemMapper.hasFakeErrorItem(taskId)) { + execTask.setResult(ResultStatus.FAKE_ERROR.name()); + } else { + execTask.setResult(ResultStatus.SUCCESS.name()); + } } execTaskMapper.updateByPrimaryKeySelective(execTask); }