From 96f7817a6655591bfa05f52ce4f99b3db2973aeb Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 31 Mar 2023 18:49:52 +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=E7=AD=89=E5=BE=85=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=BF=87=E9=95=BF=E5=AF=BC=E8=87=B4WebSocket?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E4=B8=AD=E6=96=AD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fit2-zhao --- .../listener/ApiExecutionQueueListener.java | 4 ++-- .../io/metersphere/websocket/IndexWebSocket.java | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/listener/ApiExecutionQueueListener.java b/api-test/backend/src/main/java/io/metersphere/listener/ApiExecutionQueueListener.java index 30673f4f53..686fac0e91 100644 --- a/api-test/backend/src/main/java/io/metersphere/listener/ApiExecutionQueueListener.java +++ b/api-test/backend/src/main/java/io/metersphere/listener/ApiExecutionQueueListener.java @@ -1,15 +1,15 @@ package io.metersphere.listener; +import com.fit2cloud.quartz.anno.QuartzScheduled; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.service.ApiExecutionQueueService; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class ApiExecutionQueueListener { private ApiExecutionQueueService queueService; - @Scheduled(cron = "0 0/10 0/1 * * ?") + @QuartzScheduled(cron = "0 0/10 0/1 * * ?") public void execute() { if (queueService == null) { queueService = CommonBeanFactory.getBean(ApiExecutionQueueService.class); diff --git a/api-test/backend/src/main/java/io/metersphere/websocket/IndexWebSocket.java b/api-test/backend/src/main/java/io/metersphere/websocket/IndexWebSocket.java index d91d308ad4..346a842156 100644 --- a/api-test/backend/src/main/java/io/metersphere/websocket/IndexWebSocket.java +++ b/api-test/backend/src/main/java/io/metersphere/websocket/IndexWebSocket.java @@ -1,22 +1,23 @@ package io.metersphere.websocket; +import com.fit2cloud.quartz.anno.QuartzScheduled; import io.metersphere.api.dto.MsgDTO; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.WebSocketUtil; import io.metersphere.utils.LoggerUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - import jakarta.websocket.*; import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + import java.io.IOException; @Slf4j @Component // 注册到spring @ServerEndpoint("/websocket/{reportId}") // 创建websocket服务 public class IndexWebSocket { + private final long MAX_IDLE_TIMEOUT = 180000; /** * 连接成功响应 @@ -27,6 +28,7 @@ public class IndexWebSocket { RemoteEndpoint.Async async = session.getAsyncRemote(); if (async != null) { async.sendText("CONN_SUCCEEDED"); + session.setMaxIdleTimeout(MAX_IDLE_TIMEOUT); } LoggerUtil.info("客户端: [" + reportId + "] : 连接成功!" + WebSocketUtil.ONLINE_USER_SESSIONS.size(), reportId); } @@ -65,7 +67,7 @@ public class IndexWebSocket { /** * 每一分钟群发一次心跳检查 */ - @Scheduled(cron = "0 0/1 * * * ?") + @QuartzScheduled(cron = "0 0/1 * * * ?") public void heartbeatCheck() { WebSocketUtil.sendMessageAll("heartbeat check"); }