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