refactor(fudai): 抽 run_once_basic 步骤 0.1 完整预约检查块到 run_reservation_check_block

将"开始预约检查 + 初始化队列 + 状态日志 + 高价值预约处理 + 完成日志"组合
约 35 行抽到 fudai_detail_helpers.run_reservation_check_block。

返回值约定:
- True:触发了早返回(队列满等待 / 所有预约完成重置),调用方应直接 return
- False:未触发,调用方继续

douyin_fudai.py: 712 → 683 行 (-29)
fudai_detail_helpers.py: 3213 → 3251 行

douyin_fudai.py 跌破 700 行(4121 → 683,本会话累计削减 3438 行 = -83%)
run_once_basic 函数从 124 → 95 行

验证:
- pytest 1013 passed
- compile OK

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
CodexandClaude Opus 4.7 committed 2026-05-22 13:47:44 +08:00
1 parent 48d78147b5
commit 61e37f6644
2 files changed
+43 -34

No files matched your search

+5 -34
View File
@@ -410,37 +410,12 @@ class fudai_analyse:
return
# 0.1. 若启用高价值预约:先处理"是否需要回退到预约直播间"
try:
reservation_check_start = time.time()
self._log_kv("预约", "开始预约检查", timestamp=reservation_check_start)
from douyin.core.fudai_modules.fudai_detail_helpers import (
run_reservation_check_block,
)
# 初始化预约队列(第一次运行时清空 + 写状态文件)
from douyin.core.fudai_modules.fudai_detail_helpers import (
initialize_reservations_queue,
)
initialize_reservations_queue(self)
high_value_enabled = getattr(self, "high_value_fudai_enabled", False)
reservations_list = getattr(self, "reservations", None)
reservations_count = len(reservations_list) if reservations_list else 0
# 添加详细的调试日志,确认预约回退逻辑的触发条件
from douyin.core.fudai_modules.fudai_detail_helpers import (
log_reservation_check_status,
)
log_reservation_check_status(self, high_value_enabled)
if high_value_enabled and reservations_list:
from douyin.core.fudai_modules.fudai_detail_helpers import (
process_high_value_reservation_check,
)
if process_high_value_reservation_check(self, start_time):
return
except Exception:
pass
if run_reservation_check_block(self, start_time):
return
# 检查是否刚刚记录了预约,如果是,强制切换直播间,避免在同一直播间循环
from douyin.core.fudai_modules.fudai_detail_helpers import (
@@ -450,10 +425,6 @@ class fudai_analyse:
if try_just_recorded_reservation_switch(self, start_time):
return
# 预约检查耗时记录
reservation_elapsed = time.time() - reservation_check_start
self._log_kv("预约", f"预约检查完成,耗时: {reservation_elapsed:.3f}s")
# 0.5. 检查是否需要跳过阶段检测,直接查找福袋(点击参与抽奖后)
from douyin.core.fudai_modules.fudai_detail_helpers import (
try_skip_stage_diagnosis,
@@ -273,6 +273,44 @@ def handle_no_fudai_in_live_room(analyser, room_pos_ref, start_time: float) -> N
)
def run_reservation_check_block(analyser, start_time: float) -> bool:
"""run_once_basic 步骤 0.1:完整的预约检查块。
流程:
1. 写"开始预约检查"日志
2. initialize_reservations_queue
3. log_reservation_check_status
4. 如启用高价值 + 有预约队列 → process_high_value_reservation_check
返回:
True:触发了早返回(队列满等待 / 所有预约完成重置),调用方应直接 return
False:未触发早返回,调用方继续
"""
try:
reservation_check_start = time.time()
analyser._log_kv("预约", "开始预约检查", timestamp=reservation_check_start)
initialize_reservations_queue(analyser)
high_value_enabled = getattr(analyser, "high_value_fudai_enabled", False)
reservations_list = getattr(analyser, "reservations", None)
log_reservation_check_status(analyser, high_value_enabled)
if high_value_enabled and reservations_list:
if process_high_value_reservation_check(analyser, start_time):
return True
# 预约检查耗时记录
reservation_elapsed = time.time() - reservation_check_start
analyser._log_kv(
"预约", f"预约检查完成,耗时: {reservation_elapsed:.3f}s"
)
except Exception:
pass
return False
def step1_or_step2_dispatcher(analyser, start_time: float):
"""步骤1(第二次打开)vs 步骤2(第一次打开)的分发。