feat(fam-edge): 视频生产-消费队列 - 新增 video_queue.py(生产者扫描新文件入队+重启恢复,独立消费者线程云端分析);模型消费超时按原配置×timeout_multiplier(2);failed 重试上限 max_retries(2);删除旧 watch_processor
This commit is contained in:
@@ -34,6 +34,7 @@ class OracleDB:
|
||||
self._conn = sqlite3.connect(db_path, check_same_thread=False)
|
||||
self._conn.row_factory = sqlite3.Row
|
||||
self._conn.execute("PRAGMA journal_mode=WAL")
|
||||
self._conn.execute("PRAGMA busy_timeout=10000")
|
||||
self._init_schema()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@@ -49,6 +50,7 @@ class OracleDB:
|
||||
duration_sec REAL,
|
||||
event_start_time TEXT,
|
||||
status TEXT DEFAULT 'pending',
|
||||
retry_count INTEGER DEFAULT 0,
|
||||
summary_json TEXT,
|
||||
events_json TEXT,
|
||||
people_json TEXT,
|
||||
@@ -82,6 +84,10 @@ class OracleDB:
|
||||
CREATE INDEX IF NOT EXISTS idx_videos_updated ON videos(updated_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_events_video ON events(video_id);
|
||||
""")
|
||||
# 兼容旧库:补 retry_count 列(生产-消费队列重试上限用)
|
||||
cols = [r[1] for r in c.execute("PRAGMA table_info(videos)").fetchall()]
|
||||
if 'retry_count' not in cols:
|
||||
c.execute("ALTER TABLE videos ADD COLUMN retry_count INTEGER DEFAULT 0")
|
||||
self._conn.commit()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@@ -91,6 +97,10 @@ class OracleDB:
|
||||
cur = self._conn.execute("SELECT * FROM videos WHERE filename=?", (filename,))
|
||||
return cur.fetchone()
|
||||
|
||||
def get_video_by_id(self, video_id: int) -> Optional[sqlite3.Row]:
|
||||
cur = self._conn.execute("SELECT * FROM videos WHERE id=?", (video_id,))
|
||||
return cur.fetchone()
|
||||
|
||||
def ensure_video(self, filename: str, local_path: str,
|
||||
camera_name: str = '', event_start_time: str = '',
|
||||
duration_sec: float = 0.0, drive_file_id: str = '') -> int:
|
||||
@@ -141,7 +151,8 @@ class OracleDB:
|
||||
def mark_video_failed(self, video_id: int, error: str = ''):
|
||||
now = _now_iso()
|
||||
self._conn.execute(
|
||||
"UPDATE videos SET status='failed', summary_json=?, updated_at=? WHERE id=?",
|
||||
"UPDATE videos SET status='failed', retry_count=retry_count+1, "
|
||||
"summary_json=?, updated_at=? WHERE id=?",
|
||||
(error, now, video_id))
|
||||
self._conn.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user