feat(fam-edge): 视频生产-消费队列 - 新增 video_queue.py(生产者扫描新文件入队+重启恢复,独立消费者线程云端分析);模型消费超时按原配置×timeout_multiplier(2);failed 重试上限 max_retries(2);删除旧 watch_processor
This commit is contained in:
@@ -64,8 +64,13 @@ class VideoProcessor:
|
||||
ordered.append(a)
|
||||
return ordered
|
||||
|
||||
def process_video(self, video_id: int, filename: str, local_path: str) -> bool:
|
||||
"""处理一个视频记录,返回是否成功。"""
|
||||
def process_video(self, video_id: int, filename: str, local_path: str,
|
||||
timeout_multiplier: float = 1.0) -> bool:
|
||||
"""处理一个视频记录,返回是否成功。
|
||||
|
||||
timeout_multiplier: 云端模型消费的超时放大倍数(如 2 = 在配置 timeout 上 ×2)。
|
||||
每次调用前临时放大对应 adapter.timeout,调用后恢复,避免影响其他调用方。
|
||||
"""
|
||||
if not os.path.isfile(local_path):
|
||||
logger.error(f"[video_id={video_id}] 文件不存在,跳过: {local_path}")
|
||||
self.db.mark_video_failed(video_id, "file_missing")
|
||||
@@ -88,6 +93,12 @@ class VideoProcessor:
|
||||
|
||||
last_err = "no_vision_adapter"
|
||||
for adapter in self._ordered_vision_adapters():
|
||||
# 按模型原配置超时 × multiplier(默认 1x;队列消费默认 2x)
|
||||
orig_timeout = adapter.get_timeout()
|
||||
if timeout_multiplier != 1.0:
|
||||
adapter.timeout = int(orig_timeout * timeout_multiplier)
|
||||
logger.info(f"[video_id={video_id}] {adapter.provider_name} 超时 "
|
||||
f"{orig_timeout}s -> {adapter.timeout}s (×{timeout_multiplier})")
|
||||
try:
|
||||
logger.info(f"[video_id={video_id}] 尝试 {adapter.provider_name} 整视频分析")
|
||||
result = adapter.analyze_video(local_path, known, event_start)
|
||||
@@ -95,6 +106,8 @@ class VideoProcessor:
|
||||
logger.error(f"[video_id={video_id}] {adapter.provider_name} 异常: {e}")
|
||||
last_err = str(e)
|
||||
continue
|
||||
finally:
|
||||
adapter.timeout = orig_timeout
|
||||
if result:
|
||||
self._store_result(video_id, result)
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user