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); }