refactor(fudai): 抽 _handle_live_room_has_or_not_fudai 中"锁定期内时间窗口未到"块到 should_skip_fudai_search_in_lock_period

将 49 行的早返回检查抽到 helper:
- focus_until > now_ts(在锁定期内)
- queue_full_waiting_at_earliest=True
- 队头预约 future_ts - join_ahead > now_ts → 跳过查找避免重复打开详情

返回值约定:
- True:满足跳过条件,已写完成日志,调用方应直接 return
- False:不满足,调用方继续正常流程

douyin_fudai.py: 2144 → 2102 行 (-42)
fudai_detail_helpers.py: 1614 → 1678 行

验证:
- 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 11:56:51 +08:00
1 parent c5a70d4a62
commit 23e24a9f27
2 files changed
+69 -47

No files matched your search

+5 -47
View File
@@ -2042,54 +2042,12 @@ class fudai_analyse:
pass
# 检查是否在锁定期内,且时间窗口未到,避免重复打开福袋详情
try:
now_ts = time.time()
focus_until = float(getattr(self, "reservation_focus_until_ts", 0.0) or 0.0)
queue_full_waiting = bool(
getattr(self, "queue_full_waiting_at_earliest", False) or False
)
from douyin.core.fudai_modules.fudai_detail_helpers import (
should_skip_fudai_search_in_lock_period,
)
if focus_until > 0 and now_ts < focus_until and queue_full_waiting:
# 在锁定期内,且队列满等待中,检查时间窗口
if self.reservations and len(self.reservations) > 0:
earliest = self.reservations[0]
try:
ft = float(earliest.get("future_ts") or 0.0)
if ft > 0:
join_ahead = float(
getattr(
self, "high_value_fudai_join_ahead_seconds", 100
)
or 120
)
time_window_start_ts = ft - join_ahead
# 如果时间窗口未到,避免重复打开福袋详情
if now_ts < time_window_start_ts:
try:
self._log_kv(
"预约",
"[预约] 锁定期内时间窗口未到,避免重复打开福袋详情",
focus_until=int(focus_until),
now_ts=int(now_ts),
time_window_start=int(time_window_start_ts),
remain_seconds=int(
time_window_start_ts - now_ts
),
)
except Exception:
pass
elapsed = time.time() - start_time
self._log_kv(
"流程",
"_handle_live_room_has_or_not_fudai完成(锁定期内时间窗口未到)",
elapsed_seconds=round(elapsed, 2),
)
return
except Exception:
pass
except Exception:
pass
if should_skip_fudai_search_in_lock_period(self, start_time):
return
room_pos_ref: List[int] = [0]
opened = douyin_flow_control.find_and_open_fudai_detail(self, room_pos_ref)
@@ -42,6 +42,70 @@ def log_screenshot_failed(
pass
def should_skip_fudai_search_in_lock_period(analyser, start_time: float) -> bool:
"""_handle_live_room_has_or_not_fudai 早返回:锁定期内时间窗口未到。
检查条件:
- reservation_focus_until_ts > now_ts(在锁定期内)
- queue_full_waiting_at_earliest=True(队列满等待中)
- 队头预约的 future_ts - join_ahead_seconds > now_ts(时间窗口未到)
返回:
True:满足跳过条件,已写完成日志,调用方应直接 return
False:不满足,调用方继续正常流程
"""
try:
now_ts = time.time()
focus_until = float(
getattr(analyser, "reservation_focus_until_ts", 0.0) or 0.0
)
queue_full_waiting = bool(
getattr(analyser, "queue_full_waiting_at_earliest", False) or False
)
if not (focus_until > 0 and now_ts < focus_until and queue_full_waiting):
return False
if not (analyser.reservations and len(analyser.reservations) > 0):
return False
earliest = analyser.reservations[0]
try:
ft = float(earliest.get("future_ts") or 0.0)
if ft <= 0:
return False
join_ahead = float(
getattr(analyser, "high_value_fudai_join_ahead_seconds", 100) or 120
)
time_window_start_ts = ft - join_ahead
if now_ts < time_window_start_ts:
try:
analyser._log_kv(
"预约",
"[预约] 锁定期内时间窗口未到,避免重复打开福袋详情",
focus_until=int(focus_until),
now_ts=int(now_ts),
time_window_start=int(time_window_start_ts),
remain_seconds=int(time_window_start_ts - now_ts),
)
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv(
"流程",
"_handle_live_room_has_or_not_fudai完成(锁定期内时间窗口未到)",
elapsed_seconds=round(elapsed, 2),
)
return True
except Exception:
pass
except Exception:
pass
return False
def handle_reservation_after_attend_success(analyser, future_timestamp: float) -> None:
"""参与成功后处理预约队列:清除锁定期 / 设置保护期 / 移除已完成预约。