refactor(reservation): 抽 attend_window 的"详细检查日志"块到 log_attend_window_detail_check
将 process_reservation_attend_window 中"详细调试日志"块(约 50 行)抽到 log_attend_window_detail_check helper。该块仅做日志输出,无副作用, 依赖通过参数注入:now_ts / focus_until / ft / dynamic_ahead / join_ahead / poll_before / est_back_times。 attend_window.py: 1314 → 1276 行 (-38) attend_window_helpers.py: 213 → 276 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8fea99a168
commit
4abd053957
2 files changed
+74
-49
No files matched your search
@@ -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),直接允许检查时间窗口
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in new issue
Block a user