31 lines
720 B
Python
31 lines
720 B
Python
"""
|
||
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
|