From 77351bafd48b43c901e20bb88657292ee2367635 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 11:00:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20run=5Fonce=5Fbas?= =?UTF-8?q?ic=20=E4=B8=AD"=E6=88=AA=E5=9B=BE=E5=A4=B1=E8=B4=A5=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E9=87=8D=E8=AF=95"=E6=97=A5=E5=BF=97=E5=9D=97?= =?UTF-8?q?=E5=88=B0=20log=5Fscreenshot=5Ffailed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 run_once_basic 中"获取截图失败(多次重试后仍失败)"的多字段日志块 (22 行)抽到 fudai_detail_helpers.log_screenshot_failed。 douyin_fudai.py: 3460 → 3447 行 (-13) fudai_detail_helpers.py: 83 → 120 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 25 +++-------- .../fudai_modules/fudai_detail_helpers.py | 41 ++++++++++++++++++- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 6b8c9c8..28e2f00 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1577,25 +1577,12 @@ class fudai_analyse: screenshot_elapsed = time.time() - screenshot_start if not ok: - elapsed = time.time() - start_time - self._log_kv( - "截图", - "获取截图失败(多次重试后仍失败)", - ok=0, - retries=max_screenshot_retries, - elapsed_seconds=round(elapsed, 2), - screenshot_elapsed_seconds=round(screenshot_elapsed, 2), - reservation_after_action_pending=bool( - getattr(self, "reservation_after_action_pending", False) - ), - reservation_focus_until_ts=float( - getattr(self, "reservation_focus_until_ts", 0.0) or 0.0 - ), - waiting_for_lottery=bool( - getattr(self, "_waiting_for_lottery_result", False) - ), - room_pos=int(getattr(self, "room_pos", 0) or 0), - suggestion="检查设备连接状态和ADB服务", + from douyin.core.fudai_modules.fudai_detail_helpers import ( + log_screenshot_failed, + ) + + log_screenshot_failed( + self, start_time, screenshot_elapsed, max_screenshot_retries ) return diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 8960198..aef1b10 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -1,9 +1,46 @@ -"""_handle_in_fudai_detail 辅助函数 +"""_handle_in_fudai_detail / run_once_basic 辅助函数 -从 douyin_fudai.py:_handle_in_fudai_detail 中提取的相对独立的早返回块。 +从 douyin_fudai.py 中提取的相对独立的早返回块。 """ from __future__ import annotations +import time + + +def log_screenshot_failed( + analyser, + start_time: float, + screenshot_elapsed: float, + max_retries: int, +) -> None: + """run_once_basic 步骤1:多次重试后截图仍失败时的日志记录。 + + 调用方应在调用后立即 return。 + """ + try: + elapsed = time.time() - start_time + analyser._log_kv( + "截图", + "获取截图失败(多次重试后仍失败)", + ok=0, + retries=max_retries, + elapsed_seconds=round(elapsed, 2), + screenshot_elapsed_seconds=round(screenshot_elapsed, 2), + reservation_after_action_pending=bool( + getattr(analyser, "reservation_after_action_pending", False) + ), + reservation_focus_until_ts=float( + getattr(analyser, "reservation_focus_until_ts", 0.0) or 0.0 + ), + waiting_for_lottery=bool( + getattr(analyser, "_waiting_for_lottery_result", False) + ), + room_pos=int(getattr(analyser, "room_pos", 0) or 0), + suggestion="检查设备连接状态和ADB服务", + ) + except Exception: + pass + def clear_task_count_flag(analyser) -> None: """清除任务数量标志(_fudai_detail_task_count_from_stage = None)。