预约: 在seek_reservation_room中添加总时间上限30秒,防止卡死
This commit is contained in:
1 parent
33119a8200
commit
746f24636a
1 file changed
+28
@@ -524,6 +524,10 @@ class ReservationHandler:
|
||||
target_room_title = str(item.get("room_title") or "").strip()
|
||||
target_room_title_raw = str(item.get("room_title_raw") or "").strip()
|
||||
|
||||
# 记录开始时间,防止总时间过长卡死
|
||||
seek_start_time = time.time()
|
||||
max_seek_duration = 30.0 # 最大30秒
|
||||
|
||||
# 输出目标直播间的位置和标题信息
|
||||
try:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
@@ -627,6 +631,18 @@ class ReservationHandler:
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
# 检查总时间是否超过上限
|
||||
if time.time() - seek_start_time > max_seek_duration:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
operation_type,
|
||||
f"[{operation_type}] _seek_reservation_room:总时间超过上限,停止回退",
|
||||
elapsed_seconds=time.time() - seek_start_time,
|
||||
max_duration=max_seek_duration,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
elif pos_diff < 0:
|
||||
# 目标在上方(target_pos < cur_pos),需要向上回退(减少 room_pos)
|
||||
back_times = min(abs(pos_diff), max_back) if max_back > 0 else abs(pos_diff)
|
||||
@@ -679,6 +695,18 @@ class ReservationHandler:
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 检查总时间是否超过上限
|
||||
if time.time() - seek_start_time > max_seek_duration:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
operation_type,
|
||||
f"[{operation_type}] _seek_reservation_room:总时间超过上限,停止回退",
|
||||
elapsed_seconds=time.time() - seek_start_time,
|
||||
max_duration=max_seek_duration,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
# 回退时设置标志,跳过记录标题(因为之前已经记录过了)
|
||||
try:
|
||||
analyser._skip_record_title_during_seek = True
|
||||
|
||||
Reference in new issue
Block a user