diff --git a/douyin/reservation/reservation_logic/attend_window.py b/douyin/reservation/reservation_logic/attend_window.py index f19c242..5ee2f3a 100644 --- a/douyin/reservation/reservation_logic/attend_window.py +++ b/douyin/reservation/reservation_logic/attend_window.py @@ -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 diff --git a/douyin/reservation/reservation_logic/attend_window_helpers.py b/douyin/reservation/reservation_logic/attend_window_helpers.py index 4f5d472..37946a5 100644 --- a/douyin/reservation/reservation_logic/attend_window_helpers.py +++ b/douyin/reservation/reservation_logic/attend_window_helpers.py @@ -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,