Add voice analytics filters and metrics

This commit is contained in:
2026-04-26 22:00:34 +08:00
parent 3805c18622
commit 55ca0985eb
25 changed files with 710 additions and 39 deletions

View File

@@ -6,7 +6,7 @@ from app.core.config import settings
_engine = None
_session_factory: async_sessionmaker[AsyncSession] | None = None
_lock = threading.Lock()
_lock = threading.RLock()
def _get_engine():
@@ -34,6 +34,25 @@ def _get_session_factory():
return _session_factory
async def dispose_engine():
"""Dispose the async engine and reset cached DB handles.
Celery tasks run async code through ``asyncio.run()``, which creates and closes
one event loop per task. Asyncpg connections are bound to the loop that created
them, so worker tasks must not keep pooled connections across task runs.
"""
global _engine, _session_factory
engine = _engine
if engine is not None:
await engine.dispose()
with _lock:
if _engine is engine:
_engine = None
_session_factory = None
async def init_db():
"""Create tables if they do not exist."""
from app.db.models import Base # main models