From 81b90a971a86ec87c792d7e5662e94aa4caa63e3 Mon Sep 17 00:00:00 2001 From: zqc <835569504@qq.com> Date: Thu, 5 Mar 2026 11:30:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E9=A2=84=E8=AD=A6=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84result=5Ftype=E5=88=86=E8=A7=A3=E4=B8=BA=E5=A4=9A?= =?UTF-8?q?=E4=B8=AAmsg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/base_frame_processor.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/biz/base_frame_processor.py b/biz/base_frame_processor.py index c8a3a59..1fdef68 100644 --- a/biz/base_frame_processor.py +++ b/biz/base_frame_processor.py @@ -75,6 +75,32 @@ class BaseFrameProcessorWorker(threading.Thread): raise RuntimeError("Failed to encode image to JPEG") return base64.b64encode(buf.tobytes()).decode("ascii") + def _expand_msg_by_result_type(self, msg: dict) -> list: + """ + 将 msg 中的 result_type 从数组展开为多个独立的 msg + + Args: + msg: 原始消息,result_type 为数组 + + Returns: + msg 列表,每个 msg 的 result_type 为数组中的单个元素 + """ + result_types = msg.get("result_type", []) + if not isinstance(result_types, list): + # 如果 result_type 已经是单个值,直接返回 + return [msg] + + if not result_types: + return [msg] + + result = [] + for r_type in result_types: + new_msg = msg.copy() + new_msg["result_type"] = r_type + result.append(new_msg) + + return result + def _post_alert(self, msg: dict): """异步发送告警 POST 请求(在线程池中执行)""" try: @@ -180,7 +206,10 @@ class BaseFrameProcessorWorker(threading.Thread): # 异步发送 POST 请求(提交到线程池) post_msg = msg.copy() post_msg['type'] = self.POST_TYPE - self.post_executor.submit(self._post_alert, post_msg) + # 展开 result_type 为多个独立的 msg + expanded_msgs = self._expand_msg_by_result_type(post_msg) + for expanded_msg in expanded_msgs: + self.post_executor.submit(self._post_alert, expanded_msg) except queue.Full: logger.warning("[WARN] ws_send_queue full, drop frame message")