Server: basic implementation. Not tested => no python installed; bugfix in ESP (uvicorn on port 8090)
This commit is contained in:
1 parent
3694cdf207
commit
8a51e3d95e
38 files changed
+2442
-21
No files matched your search
@@ -0,0 +1,35 @@
|
||||
"""Engine and session factory.
|
||||
|
||||
Synchronous SQLAlchemy, deliberately. At one camera and a few thousand frames a
|
||||
day the async machinery buys nothing and costs clarity, and the worker's
|
||||
``FOR UPDATE SKIP LOCKED`` loop is far easier to reason about synchronously.
|
||||
FastAPI runs ``def`` handlers in a threadpool, so this does not block the loop.
|
||||
Revisit only if the MJPEG relay (Phase 6) turns out to want it.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
|
||||
from .config import get_settings
|
||||
|
||||
_settings = get_settings()
|
||||
|
||||
engine = create_engine(
|
||||
_settings.database_url,
|
||||
pool_size=_settings.db_pool_size,
|
||||
pool_pre_ping=True,
|
||||
echo=_settings.db_echo,
|
||||
future=True,
|
||||
)
|
||||
|
||||
SessionLocal = sessionmaker(bind=engine, expire_on_commit=False, future=True)
|
||||
|
||||
|
||||
def session_scope() -> Iterator[Session]:
|
||||
"""Context-managed session for scripts and the worker."""
|
||||
with SessionLocal() as session:
|
||||
yield session
|
||||
Reference in new issue
Block a user