Add voice analytics filters and metrics
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user