From 8a44389761678a91f25b9045cc13b5c3ba4c0143 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Wed, 24 Apr 2024 11:44:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=B2=E8=A1=8C=E9=9B=86=E5=90=88=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E6=97=A0=E6=B3=95=E5=81=9C=E6=AD=A2=E7=9A=84=E7=BC=BA?= =?UTF-8?q?=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/listener/MessageListener.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 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 6ed6933ef2..a0b6bc30f0 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 @@ -1,6 +1,8 @@ package io.metersphere.api.listener; import io.metersphere.api.event.ApiEventSource; +import io.metersphere.api.mapper.ApiReportMapper; +import io.metersphere.api.mapper.ApiScenarioReportMapper; import io.metersphere.api.service.ApiReportSendNoticeService; import io.metersphere.api.service.definition.ApiReportService; import io.metersphere.api.service.definition.ApiTestCaseBatchRunService; @@ -41,9 +43,9 @@ public class MessageListener { @Resource private ApiScenarioBatchRunService apiScenarioBatchRunService; @Resource - private ApiReportService apiReportService; + private ApiReportMapper apiReportMapper; @Resource - private ApiScenarioReportService apiScenarioReportService; + private ApiScenarioReportMapper apiScenarioReportMapper; @KafkaListener(id = MESSAGE_CONSUME_ID, topics = KafkaTopicConstants.API_REPORT_TASK_TOPIC, groupId = MESSAGE_CONSUME_ID) public void messageConsume(ConsumerRecord record) { @@ -58,6 +60,19 @@ public class MessageListener { // TODO 通知测试计划处理后续 LogUtils.info("发送通知给测试计划:{}", record.key()); apiEventSource.fireEvent(ApplicationScope.API_TEST, record.value()); + }else { + ApiExecuteResourceType resourceType = EnumValidator.validateEnum(ApiExecuteResourceType.class, dto.getResourceType()); + boolean isStop = switch (resourceType) { + case API_CASE -> StringUtils.equals(apiReportMapper.selectByPrimaryKey(dto.getReportId()).getStatus(), ApiReportStatus.STOPPED.name()) + && deleteQueue(dto.getQueueId()); + case API_SCENARIO -> StringUtils.equals(apiScenarioReportMapper.selectByPrimaryKey(dto.getReportId()).getStatus(), ApiReportStatus.STOPPED.name()) + && deleteQueue(dto.getQueueId()); + default -> false; + }; + + if (isStop) { + return; + } } executeNextTask(dto); @@ -67,6 +82,10 @@ public class MessageListener { } } + private boolean deleteQueue(String queueId) { + apiExecutionQueueService.deleteQueue(queueId); + return true; + } /** * 执行批量的下一个任务 *