refactor(reservation): 抽 process_reservation_attend_window 中"回退后等待直播间加载"块到 wait_after_seek_and_verify
将 43 行的等待逻辑抽到 helper: - 读 reservation_back_verify_wait_seconds(默认 5.0,限制 0.1-10.0) - 写"开始等待"日志 - 调用 operation.delay 或 time.sleep - 写"等待完成"日志(含实际等待秒数) attend_window.py: 1030 → 991 行 (-39) attend_window_helpers.py: 645 → 699 行 attend_window.py 跌破 1000 行(1437 → 991,本会话累计削减 446 行 = -31%) 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
6aec4ae314
commit
dadb0b6852
2 files changed
+57
-42
No files matched your search
@@ -418,49 +418,10 @@ def process_reservation_attend_window(
|
||||
pass
|
||||
|
||||
if verify_enabled:
|
||||
# 回退操作后等待直播间加载完成,然后再进行校验
|
||||
# 使用配置项控制等待时间,默认3秒(确保直播间标题等信息加载完成)
|
||||
try:
|
||||
verify_wait_seconds = float(
|
||||
getattr(analyser, "reservation_back_verify_wait_seconds", 5.0)
|
||||
or 5.0
|
||||
)
|
||||
if verify_wait_seconds < 0.1:
|
||||
verify_wait_seconds = 0.1 # 最小0.1秒
|
||||
if verify_wait_seconds > 10.0:
|
||||
verify_wait_seconds = 10.0 # 最大10秒,避免等待过久
|
||||
except Exception:
|
||||
verify_wait_seconds = 3.0
|
||||
# 回退操作后等待直播间加载完成
|
||||
from .attend_window_helpers import wait_after_seek_and_verify
|
||||
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window:回退后等待直播间加载完成(开始等待)",
|
||||
verify_wait_seconds=verify_wait_seconds,
|
||||
level="INFO",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 记录等待开始时间,并在等待结束后写入实际等待时长,便于验证配置是否生效
|
||||
wait_start_ts = time.time()
|
||||
try:
|
||||
try:
|
||||
analyser.operation.delay(verify_wait_seconds)
|
||||
except Exception:
|
||||
time.sleep(verify_wait_seconds)
|
||||
finally:
|
||||
waited = time.time() - wait_start_ts
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window:回退等待完成",
|
||||
expected_wait_seconds=verify_wait_seconds,
|
||||
waited_seconds=round(waited, 3),
|
||||
level="INFO",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
wait_after_seek_and_verify(analyser)
|
||||
|
||||
try:
|
||||
try:
|
||||
|
||||
@@ -105,6 +105,60 @@ def log_attend_window_detail_check(
|
||||
pass
|
||||
|
||||
|
||||
def wait_after_seek_and_verify(analyser: Any) -> float:
|
||||
"""回退操作成功后:等待直播间加载完成(写日志 + delay),返回实际等待秒数。
|
||||
|
||||
流程:
|
||||
- 读 reservation_back_verify_wait_seconds(默认 5.0,限制 0.1-10.0)
|
||||
- 写"开始等待"日志
|
||||
- 调用 operation.delay 或 time.sleep
|
||||
- 写"等待完成"日志
|
||||
"""
|
||||
import time as _time
|
||||
|
||||
try:
|
||||
verify_wait_seconds = float(
|
||||
getattr(analyser, "reservation_back_verify_wait_seconds", 5.0) or 5.0
|
||||
)
|
||||
if verify_wait_seconds < 0.1:
|
||||
verify_wait_seconds = 0.1
|
||||
if verify_wait_seconds > 10.0:
|
||||
verify_wait_seconds = 10.0
|
||||
except Exception:
|
||||
verify_wait_seconds = 3.0
|
||||
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window:回退后等待直播间加载完成(开始等待)",
|
||||
verify_wait_seconds=verify_wait_seconds,
|
||||
level="INFO",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
wait_start_ts = _time.time()
|
||||
try:
|
||||
try:
|
||||
analyser.operation.delay(verify_wait_seconds)
|
||||
except Exception:
|
||||
_time.sleep(verify_wait_seconds)
|
||||
finally:
|
||||
waited = _time.time() - wait_start_ts
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window:回退等待完成",
|
||||
expected_wait_seconds=verify_wait_seconds,
|
||||
waited_seconds=round(waited, 3),
|
||||
level="INFO",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return verify_wait_seconds
|
||||
|
||||
|
||||
def log_seek_failure_and_finish(
|
||||
analyser: Any,
|
||||
target: ReservationItem,
|
||||
|
||||
Reference in new issue
Block a user