update:增加ws连接时长,避免ws时间过短到只conn对象销毁丢失无法使用

This commit is contained in:
hrz
2025-05-21 10:43:48 +08:00
parent b8da0714c2
commit bc6c85c6c6
3 changed files with 11 additions and 8 deletions
@@ -89,7 +89,7 @@ public class ServerSideManageController {
try (WebSocketClientManager client = new WebSocketClientManager.Builder() try (WebSocketClientManager client = new WebSocketClientManager.Builder()
.connectTimeout(3, TimeUnit.SECONDS) .connectTimeout(3, TimeUnit.SECONDS)
.maxSessionDuration(5, TimeUnit.SECONDS) .maxSessionDuration(120, TimeUnit.SECONDS)
.uri(targetWsUri) .uri(targetWsUri)
.headers(headers) .headers(headers)
.build()) { .build()) {
@@ -104,8 +104,9 @@ public class ServerSideManageController {
return false; return false;
} }
try { try {
return ServerActionResponseDTO ServerActionResponseDTO response = objectMapper.readValue(jsonText, ServerActionResponseDTO.class);
.isSuccess(objectMapper.readValue(jsonText, ServerActionResponseDTO.class)); Boolean isSuccess = ServerActionResponseDTO.isSuccess(response);
return isSuccess;
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
return false; return false;
} }
+2 -2
View File
@@ -139,7 +139,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取ws服务端列表失败:', err) console.error('获取ws服务端列表失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getWsServerList(params, callback) this.getWsServerList(params, callback)
@@ -156,7 +156,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.sendWsServerAction(data, callback) this.sendWsServerAction(data, callback)
}) })
+5 -3
View File
@@ -82,11 +82,13 @@ class WebSocketServer:
if new_config is None: if new_config is None:
self.logger.bind(tag=TAG).error("获取新配置失败") self.logger.bind(tag=TAG).error("获取新配置失败")
return False return False
self.logger.bind(tag=TAG).info(f"获取新配置成功")
# 检查 VAD 和 ASR 类型是否需要更新 # 检查 VAD 和 ASR 类型是否需要更新
update_vad = check_vad_update(self.config, new_config) update_vad = check_vad_update(self.config, new_config)
update_asr = check_asr_update(self.config, new_config) update_asr = check_asr_update(self.config, new_config)
self.logger.bind(tag=TAG).info(
f"检查VAD和ASR类型是否需要更新: {update_vad} {update_asr}"
)
# 更新配置 # 更新配置
self.config = new_config self.config = new_config
# 重新初始化组件 # 重新初始化组件
@@ -114,7 +116,7 @@ class WebSocketServer:
self._intent = modules["intent"] self._intent = modules["intent"]
if "memory" in modules: if "memory" in modules:
self._memory = modules["memory"] self._memory = modules["memory"]
self.logger.bind(tag=TAG).info(f"更新配置任务执行完毕")
return True return True
except Exception as e: except Exception as e:
self.logger.bind(tag=TAG).error(f"更新服务器配置失败: {str(e)}") self.logger.bind(tag=TAG).error(f"更新服务器配置失败: {str(e)}")