refactor(reservation): 抽 process_reservation_attend_window 末尾"回退失败"块到 log_seek_failure_and_finish

将函数末尾"回退失败:记录日志,等待后续重试或清理"块(约 36 行)抽到 helper:
- 写"回退失败"日志
- 调用 write_state_callback
- 写"未触发回退"完成日志

attend_window.py: 1059 → 1030 行 (-29)
attend_window_helpers.py: 594 → 645 行

验证:
- 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:53:27 +08:00
1 parent 4ce62a1907
commit 6aec4ae314
2 files changed
+55 -33

No files matched your search

@@ -1019,40 +1019,11 @@ def process_reservation_attend_window(
return True
# 回退失败:记录日志,等待后续重试或清理
try:
analyser._log_kv(
"预约",
"[预约] 回退到预约直播间失败,保留队列以便后续重试或清理",
future_ts=int(ft),
now_ts=int(now_ts),
remain_seconds_to_open=int(ft - now_ts),
target_pos=int(target.get("pos_seen", 0)),
current_room_pos=int(room_pos),
)
except Exception:
pass
from .attend_window_helpers import log_seek_failure_and_finish
try:
write_state_callback()
except Exception:
pass
# 添加函数完成日志
try:
from datetime import datetime
elapsed = time.time() - start_time
analyser._log_kv(
"预约",
"[预约] process_reservation_attend_window 返回结果",
result="未触发回退",
future_ts=int(ft) if ft > 0 else 0,
now_ts=int(now_ts),
remain_seconds_to_open=int(ft - now_ts) if ft > now_ts else 0,
elapsed_seconds=round(elapsed, 3),
)
except Exception:
pass
log_seek_failure_and_finish(
analyser, target, ft, now_ts, room_pos, start_time, write_state_callback
)
return False
@@ -105,6 +105,57 @@ def log_attend_window_detail_check(
pass
def log_seek_failure_and_finish(
analyser: Any,
target: ReservationItem,
ft: float,
now_ts: float,
room_pos: int,
start_time: float,
write_state_callback: Callable[[], None],
) -> None:
"""process_reservation_attend_window 末尾"回退失败"块。
流程:
1. 写"回退到预约直播间失败"日志
2. 调用 write_state_callback
3. 写"未触发回退"完成日志
"""
import time as _time
try:
analyser._log_kv(
"预约",
"[预约] 回退到预约直播间失败,保留队列以便后续重试或清理",
future_ts=int(ft),
now_ts=int(now_ts),
remain_seconds_to_open=int(ft - now_ts),
target_pos=int(target.get("pos_seen", 0)),
current_room_pos=int(room_pos),
)
except Exception:
pass
try:
write_state_callback()
except Exception:
pass
try:
elapsed = _time.time() - start_time
analyser._log_kv(
"预约",
"[预约] process_reservation_attend_window 返回结果",
result="未触发回退",
future_ts=int(ft) if ft > 0 else 0,
now_ts=int(now_ts),
remain_seconds_to_open=int(ft - now_ts) if ft > now_ts else 0,
elapsed_seconds=round(elapsed, 3),
)
except Exception:
pass
def execute_seek_reservation_with_logging(
analyser: Any,
target: ReservationItem,