feat(backend): move product pricing to async persisted jobs
This commit is contained in:
parent
c869f88db2
commit
0e439b4ca7
18 changed files with 468 additions and 67 deletions
|
|
@ -7,8 +7,9 @@ load_dotenv() # load .env before db.py reads DATABASE_URL
|
|||
|
||||
from fastapi import FastAPI # noqa: E402
|
||||
from fastapi.middleware.cors import CORSMiddleware # noqa: E402
|
||||
from sqlmodel import Session # noqa: E402
|
||||
|
||||
from db import create_db_and_tables # noqa: E402
|
||||
from db import create_db_and_tables, engine # noqa: E402
|
||||
from innercontext.api import ( # noqa: E402
|
||||
ai_logs,
|
||||
health,
|
||||
|
|
@ -17,11 +18,18 @@ from innercontext.api import ( # noqa: E402
|
|||
routines,
|
||||
skincare,
|
||||
)
|
||||
from innercontext.services.pricing_jobs import enqueue_pricing_recalc # noqa: E402
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||
create_db_and_tables()
|
||||
try:
|
||||
with Session(engine) as session:
|
||||
enqueue_pricing_recalc(session)
|
||||
session.commit()
|
||||
except Exception as exc: # pragma: no cover
|
||||
print(f"[startup] failed to enqueue pricing recalculation job: {exc}")
|
||||
yield
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue