refactor(fudai): 抽 run_once_basic 中"预约队列满等待"块到 try_handle_queue_full_wait

将"队列已满 + 未在等待最早开奖"判定块(约 33 行)抽到 helper:
- 检查 reservations 数量 >= max_reservations 且 queue_full_waiting_at_earliest=False
- 满足时调用 douyin_reservation_logic.handle_queue_full_wait_at_earliest
- 成功 → 设置 queue_full_waiting_at_earliest 和 focus_until + 写完成日志

返回值约定:
- True:队列已满且已回退等待,调用方应直接 return
- False:队列未满或未触发回退,调用方继续

douyin_fudai.py: 1670 → 1648 行 (-22)
fudai_detail_helpers.py: 2273 → 2328 行

验证:
- 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 12:17:37 +08:00
1 parent 43da92f6e6
commit 722b57a7b9
2 files changed
+67 -34

No files matched your search

+12 -34
View File
@@ -777,42 +777,20 @@ class fudai_analyse:
return False
# 检查队列是否已满且需要等待
max_reservations = int(
getattr(self, "high_value_fudai_max_reservations", 3) or 3
from douyin.core.fudai_modules.fudai_detail_helpers import (
try_handle_queue_full_wait,
)
if (
len(self.reservations) >= max_reservations
and not self.queue_full_waiting_at_earliest
if try_handle_queue_full_wait(
self,
focus_ref,
_swipe_down_once,
_seek_reservation_room,
_sort_reservations,
_write_state,
start_time,
):
# 队列已满,回退到最早开奖的预约直播间等待
waiting = (
douyin_reservation_logic.handle_queue_full_wait_at_earliest(
analyser=self,
reservations=self.reservations,
room_pos=int(getattr(self, "room_pos", 0) or 0),
reservation_focus_until_ts_ref=focus_ref,
reservation_back_swipe_delay_s=float(
self.reservation_back_swipe_delay or 0.6
),
swipe_down_back_callback=_swipe_down_once,
seek_reservation_room_callback=_seek_reservation_room,
sort_reservations_callback=_sort_reservations,
write_state_callback=_write_state,
)
)
if waiting:
self.queue_full_waiting_at_earliest = True
if focus_ref:
self.reservation_focus_until_ts = float(focus_ref[0] or 0.0)
# 已回退到最早开奖的预约直播间,本轮结束
# 注意:旧版可能会设置直接参与标志,已删除该标志逻辑,走正常流程
elapsed = time.time() - start_time
self._log_kv(
"流程",
"run_once_basic完成(预约队列满等待)",
elapsed_seconds=round(elapsed, 2),
)
return
return
# 如果正在等待开奖,跳过预约回退检查
if getattr(self, "_waiting_for_lottery_result", False):
@@ -42,6 +42,61 @@ def log_screenshot_failed(
pass
def try_handle_queue_full_wait(
analyser,
focus_ref,
swipe_down_back_callback,
seek_reservation_room_callback,
sort_reservations_callback,
write_state_callback,
start_time: float,
) -> bool:
"""run_once_basic 步骤 0.1.4:检查队列是否已满,已满则回退到最早开奖的预约直播间等待。
返回:
True:队列已满且已回退等待,调用方应直接 return
False:队列未满或未触发回退,调用方继续
"""
from douyin.reservation import reservation_logic as douyin_reservation_logic
max_reservations = int(
getattr(analyser, "high_value_fudai_max_reservations", 3) or 3
)
if not (
len(analyser.reservations) >= max_reservations
and not analyser.queue_full_waiting_at_earliest
):
return False
waiting = douyin_reservation_logic.handle_queue_full_wait_at_earliest(
analyser=analyser,
reservations=analyser.reservations,
room_pos=int(getattr(analyser, "room_pos", 0) or 0),
reservation_focus_until_ts_ref=focus_ref,
reservation_back_swipe_delay_s=float(
analyser.reservation_back_swipe_delay or 0.6
),
swipe_down_back_callback=swipe_down_back_callback,
seek_reservation_room_callback=seek_reservation_room_callback,
sort_reservations_callback=sort_reservations_callback,
write_state_callback=write_state_callback,
)
if not waiting:
return False
analyser.queue_full_waiting_at_earliest = True
if focus_ref:
analyser.reservation_focus_until_ts = float(focus_ref[0] or 0.0)
elapsed = time.time() - start_time
analyser._log_kv(
"流程",
"run_once_basic完成(预约队列满等待)",
elapsed_seconds=round(elapsed, 2),
)
return True
def cleanup_expired_reservations_single_room(analyser, write_state_callback) -> None:
"""run_once_basic 单间模式(needswitch=False)下清理过期预约。