I hate this fucking language.
This commit is contained in:
+16
-1
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import pathlib
|
||||
from contextlib import asynccontextmanager
|
||||
from datetime import datetime
|
||||
@@ -9,7 +11,7 @@ from fastapi import Depends, FastAPI, HTTPException, Request
|
||||
from fastapi.responses import FileResponse, JSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from server.ai import get_oracle, get_roast_of_the_day
|
||||
from server.ai import generate_daily_motivation, get_oracle, get_roast_of_the_day
|
||||
from server.auth import create_token, require_auth, verify_pin
|
||||
from server.config_loader import load_meds_config, slot_to_dict, today_str
|
||||
from server.db import ensure_schema, get_db, new_id, utc_now_iso
|
||||
@@ -21,6 +23,18 @@ from server.slots import build_today
|
||||
from server.stats import build_history, check_milestones, compute_stats, MILESTONE_DEFS
|
||||
|
||||
NO_STORE = {"Cache-Control": "no-store"}
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def _ensure_today_motivation() -> None:
|
||||
config = load_meds_config()
|
||||
db = await get_db()
|
||||
try:
|
||||
await generate_daily_motivation(db, config.timezone)
|
||||
except Exception:
|
||||
logger.exception("Startup motivation generation failed")
|
||||
finally:
|
||||
await db.close()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
@@ -29,6 +43,7 @@ async def lifespan(app: FastAPI):
|
||||
await ensure_schema(db)
|
||||
await db.close()
|
||||
start_scheduler()
|
||||
asyncio.create_task(_ensure_today_motivation())
|
||||
yield
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user