From b5d33ef629d6eb2884e7e8b8f5fed852beddd4e6 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Thu, 4 Jul 2024 13:03:58 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20pipeline=20?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=97=B6=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/core/entities.py | 3 +++ pkg/pipeline/controller.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/core/entities.py b/pkg/core/entities.py index 7f7088c4..6305a0ec 100644 --- a/pkg/core/entities.py +++ b/pkg/core/entities.py @@ -73,6 +73,9 @@ class Query(pydantic.BaseModel): resp_message_chain: typing.Optional[list[mirai.MessageChain]] = None """回复消息链,从resp_messages包装而得""" + # ======= 内部保留 ======= + current_stage: "pkg.pipeline.stagemgr.StageInstContainer" = None + class Config: arbitrary_types_allowed = True diff --git a/pkg/pipeline/controller.py b/pkg/pipeline/controller.py index e63a2a64..677db31d 100644 --- a/pkg/pipeline/controller.py +++ b/pkg/pipeline/controller.py @@ -122,6 +122,8 @@ async def _execute_from_stage( while i < len(self.ap.stage_mgr.stage_containers): stage_container = self.ap.stage_mgr.stage_containers[i] + + query.current_stage = stage_container # 标记到 Query 对象里 result = stage_container.inst.process(query, stage_container.inst_name) @@ -162,7 +164,7 @@ async def process_query(self, query: entities.Query): try: await self._execute_from_stage(0, query) except Exception as e: - self.ap.logger.error(f"处理请求时出错 query_id={query.query_id}: {e}") + self.ap.logger.error(f"处理请求时出错 query_id={query.query_id} stage={query.current_stage.inst_name} : {e}") self.ap.logger.debug(f"Traceback: {traceback.format_exc()}") # traceback.print_exc() finally: