INNER CODE UNIT · Python
lifespan
slive777/OpenAver · web/app.py:106
async def lifespan(app: FastAPI):
# ── startup ───────────────────────────────────────────────
# 資料根定版必須在 init_db()/任何 request 之前(CD-B2);失敗走固定 stderr + os._exit。
try:
bootstrap_data_layout()
except Exception as e:
logger.error("lifespan: 資料根定版失敗: %s", e, exc_info=True)
# ruff T201 禁 print;行為等同 print(..., file=sys.stderr)
sys.stderr.write(_LIFESPAN_BOOTSTRAP_STDERR + "\n")
sys.stderr.flush()
os._exit(LIFESPAN_BOOTSTRAP_EXIT_CODE)
# init_db() 必須在任何 request 前執行:執行 DROP COLUMN migration(v0.8.7:
# 移除 legacy clip_embedding / clip_model_id),確保 Video.from_row cls(**data)
# 不會因 legacy schema 欄位收到未知 keyword 而 500。CD-57b-8 contract。
init_db()
start_notification_persistence()
_pending = consume_pending_bootstrap_result()