refactor(fudai): 抽 run_once_basic 中"预约回退触发条件日志"块到 log_reservation_check_status
将 65 行的纯日志块抽到 fudai_detail_helpers.log_reservation_check_status。 输出 3 类日志(无副作用): 1. 触发条件详情(含队列前 3 项) 2. high_value_enabled=False 时的提示 3. 队列为空时的提示 douyin_fudai.py: 2558 → 2503 行 (-55) fudai_detail_helpers.py: 1198 → 1266 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a90a885a51
commit
7694e233f9
2 files changed
+72
-59
No files matched your search
@@ -741,66 +741,11 @@ class fudai_analyse:
|
||||
reservations_count = len(reservations_list) if reservations_list else 0
|
||||
|
||||
# 添加详细的调试日志,确认预约回退逻辑的触发条件
|
||||
try:
|
||||
# 输出预约队列的详细信息
|
||||
reservations_detail = []
|
||||
if reservations_list:
|
||||
for idx, r in enumerate(reservations_list[:3]): # 只显示前3个
|
||||
try:
|
||||
ft = float(r.get("future_ts") or 0)
|
||||
from datetime import datetime
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
log_reservation_check_status,
|
||||
)
|
||||
|
||||
ft_str = (
|
||||
datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S")
|
||||
if ft > 0
|
||||
else "无效"
|
||||
)
|
||||
reservations_detail.append(
|
||||
{
|
||||
"index": idx,
|
||||
"future_ts": int(ft) if ft > 0 else 0,
|
||||
"future_str": ft_str,
|
||||
"value": float(r.get("prize_value_yuan", 0)),
|
||||
"pos_seen": int(r.get("pos_seen", 0)),
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self._log_kv(
|
||||
"预约",
|
||||
"[预约] run_once_basic:检查预约回退触发条件",
|
||||
high_value_enabled=high_value_enabled,
|
||||
reservations_count=reservations_count,
|
||||
reservations_is_none=(reservations_list is None),
|
||||
will_check_reservations=bool(
|
||||
high_value_enabled and reservations_list
|
||||
),
|
||||
reservations_detail=reservations_detail,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 如果预约功能未启用,输出日志
|
||||
if not high_value_enabled:
|
||||
try:
|
||||
self._log_kv(
|
||||
"预约",
|
||||
"[预约] 预约功能未启用(high_value_fudai_enabled=False),跳过预约回退检查",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 如果预约队列为空,输出日志
|
||||
elif not reservations_list or reservations_count == 0:
|
||||
try:
|
||||
self._log_kv(
|
||||
"预约",
|
||||
"[预约] 预约队列为空,跳过预约回退检查",
|
||||
reservations_is_none=(reservations_list is None),
|
||||
reservations_count=reservations_count,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
log_reservation_check_status(self, high_value_enabled)
|
||||
|
||||
if high_value_enabled and reservations_list:
|
||||
|
||||
|
||||
@@ -42,6 +42,74 @@ def log_screenshot_failed(
|
||||
pass
|
||||
|
||||
|
||||
def log_reservation_check_status(analyser, high_value_enabled: bool) -> None:
|
||||
"""run_once_basic 步骤 0.1.2:记录预约回退的触发条件日志(纯日志,无副作用)。
|
||||
|
||||
输出 3 条日志:
|
||||
1. [预约] run_once_basic:检查预约回退触发条件(含队列前 3 项详情)
|
||||
2. 若 high_value_enabled=False:[预约] 预约功能未启用,跳过预约回退检查
|
||||
3. 若 high_value_enabled=True 但队列为空:[预约] 预约队列为空,跳过预约回退检查
|
||||
"""
|
||||
reservations_list = getattr(analyser, "reservations", None)
|
||||
reservations_count = len(reservations_list) if reservations_list else 0
|
||||
|
||||
try:
|
||||
from datetime import datetime
|
||||
|
||||
reservations_detail = []
|
||||
if reservations_list:
|
||||
for idx, r in enumerate(reservations_list[:3]):
|
||||
try:
|
||||
ft = float(r.get("future_ts") or 0)
|
||||
ft_str = (
|
||||
datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S")
|
||||
if ft > 0
|
||||
else "无效"
|
||||
)
|
||||
reservations_detail.append(
|
||||
{
|
||||
"index": idx,
|
||||
"future_ts": int(ft) if ft > 0 else 0,
|
||||
"future_str": ft_str,
|
||||
"value": float(r.get("prize_value_yuan", 0)),
|
||||
"pos_seen": int(r.get("pos_seen", 0)),
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] run_once_basic:检查预约回退触发条件",
|
||||
high_value_enabled=high_value_enabled,
|
||||
reservations_count=reservations_count,
|
||||
reservations_is_none=(reservations_list is None),
|
||||
will_check_reservations=bool(high_value_enabled and reservations_list),
|
||||
reservations_detail=reservations_detail,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not high_value_enabled:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 预约功能未启用(high_value_fudai_enabled=False),跳过预约回退检查",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
elif not reservations_list or reservations_count == 0:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 预约队列为空,跳过预约回退检查",
|
||||
reservations_is_none=(reservations_list is None),
|
||||
reservations_count=reservations_count,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def write_reservations_state_throttled(analyser) -> None:
|
||||
"""run_once_basic 中的 _write_state 回调实现:将预约队列写入状态文件。
|
||||
|
||||
|
||||
Reference in new issue
Block a user