diff --git a/douyin/reservation/reservation_logic/attend_window.py b/douyin/reservation/reservation_logic/attend_window.py index fe23948..a55e3a5 100644 --- a/douyin/reservation/reservation_logic/attend_window.py +++ b/douyin/reservation/reservation_logic/attend_window.py @@ -286,56 +286,18 @@ def process_reservation_attend_window( dynamic_ahead = int(join_ahead) # 添加详细的调试日志:记录锁定期状态和时间窗口检查结果 - try: - from datetime import datetime + from .attend_window_helpers import log_attend_window_detail_check - now_str = datetime.fromtimestamp(now_ts).strftime("%Y-%m-%d %H:%M:%S") - time_window_start_ts = ft - dynamic_ahead - time_window_start_str = ( - datetime.fromtimestamp(time_window_start_ts).strftime("%Y-%m-%d %H:%M:%S") - if time_window_start_ts > 0 - else "无效" - ) - time_window_end_ts = ft + max(0.0, poll_before) - time_window_end_str = ( - datetime.fromtimestamp(time_window_end_ts).strftime("%Y-%m-%d %H:%M:%S") - if time_window_end_ts > 0 - else "无效" - ) - ft_str = ( - datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") - if ft > 0 - else "无效" - ) - - analyser._log_kv( - "预约", - "[预约] process_reservation_attend_window 详细检查", - now_ts=int(now_ts), - now_str=now_str, - focus_until=int(focus_until) if focus_until > 0 else 0, - target_future_ts=int(ft), - target_future_str=ft_str, - dynamic_ahead=dynamic_ahead, - join_ahead=join_ahead, - poll_before=poll_before, - est_back_times=est_back_times, - time_window_start=int(time_window_start_ts), - time_window_start_str=time_window_start_str, - time_window_end=int(time_window_end_ts), - time_window_end_str=time_window_end_str, - remain_seconds_to_open=int(ft - now_ts) if ft > now_ts else 0, - remain_seconds_to_window=( - int(time_window_start_ts - now_ts) - if time_window_start_ts > now_ts - else 0 - ), - in_lock_period=bool(focus_until > 0 and now_ts < focus_until), - in_time_window=bool(now_ts >= time_window_start_ts), - passed_time_window=bool(now_ts > time_window_end_ts), - ) - except Exception: - pass + log_attend_window_detail_check( + analyser, + now_ts, + focus_until, + ft, + dynamic_ahead, + join_ahead, + poll_before, + est_back_times, + ) # 优化锁定期检查: # 1. 如果没有锁定期(focus_until = 0),直接允许检查时间窗口 diff --git a/douyin/reservation/reservation_logic/attend_window_helpers.py b/douyin/reservation/reservation_logic/attend_window_helpers.py index a35c6b5..7200d31 100644 --- a/douyin/reservation/reservation_logic/attend_window_helpers.py +++ b/douyin/reservation/reservation_logic/attend_window_helpers.py @@ -42,6 +42,69 @@ def check_total_timeout( return False +def log_attend_window_detail_check( + analyser: Any, + now_ts: float, + focus_until: float, + ft: float, + dynamic_ahead: int, + join_ahead: float, + poll_before: float, + est_back_times: int, +) -> None: + """记录"详细检查"日志(锁定期状态 + 时间窗口)。纯日志,无副作用。""" + try: + from datetime import datetime + + now_str = datetime.fromtimestamp(now_ts).strftime("%Y-%m-%d %H:%M:%S") + time_window_start_ts = ft - dynamic_ahead + time_window_start_str = ( + datetime.fromtimestamp(time_window_start_ts).strftime("%Y-%m-%d %H:%M:%S") + if time_window_start_ts > 0 + else "无效" + ) + time_window_end_ts = ft + max(0.0, poll_before) + time_window_end_str = ( + datetime.fromtimestamp(time_window_end_ts).strftime("%Y-%m-%d %H:%M:%S") + if time_window_end_ts > 0 + else "无效" + ) + ft_str = ( + datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") + if ft > 0 + else "无效" + ) + + analyser._log_kv( + "预约", + "[预约] process_reservation_attend_window 详细检查", + now_ts=int(now_ts), + now_str=now_str, + focus_until=int(focus_until) if focus_until > 0 else 0, + target_future_ts=int(ft), + target_future_str=ft_str, + dynamic_ahead=dynamic_ahead, + join_ahead=join_ahead, + poll_before=poll_before, + est_back_times=est_back_times, + time_window_start=int(time_window_start_ts), + time_window_start_str=time_window_start_str, + time_window_end=int(time_window_end_ts), + time_window_end_str=time_window_end_str, + remain_seconds_to_open=int(ft - now_ts) if ft > now_ts else 0, + remain_seconds_to_window=( + int(time_window_start_ts - now_ts) + if time_window_start_ts > now_ts + else 0 + ), + in_lock_period=bool(focus_until > 0 and now_ts < focus_until), + in_time_window=bool(now_ts >= time_window_start_ts), + passed_time_window=bool(now_ts > time_window_end_ts), + ) + except Exception: + pass + + def _write_state_unified( write_state_callback: Callable[[], None],