Files
sentinel-home-ai/fam-edge/src/fam_edge/state.py

31 lines
720 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
state - 进程内共享单例OracleDB / VideoQueue 实例)
video_queue / person_service / api_gateway 都通过 get_db() 访问同一个 SQLite 连接,
避免重复打开与循环 import。
"""
from . import oracle_db
from .config_loader import load_config
_db = None
_queue = None
def get_db() -> oracle_db.OracleDB:
global _db
if _db is None:
cfg = load_config()
path = cfg.get('oracle_db', {}).get('path', '/opt/fam-edge/data/oracle.db')
_db = oracle_db.OracleDB(path)
return _db
def set_queue(q):
"""注册 VideoQueue 实例app 启动时调用api_gateway 读取实时状态)。"""
global _queue
_queue = q
def get_queue():
return _queue