WP-03: FastAPI Lifespan Hooks #90
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-reviewing
ai-working
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
security
tech-debt
todo
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#90
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Wire
get_browser()andshutdown_browser()into FastAPI's lifespan so the browser warms up on startup and cleans up on shutdown.Repo:
databasePhase: 0 (Render Pipeline Optimization)
Dependencies: WP-02
Complexity: S
Current State
app/main.pyline 54: plainFastAPI(...)constructor with no lifespanImplementation
@asynccontextmanagerlifespan function that callsget_browser()on startup andshutdown_browser()on shutdownlifespan=lifespantoFastAPI()constructorFiles
database/app/main.py— add lifespan hook, pass to FastAPI constructordatabase/app/routers_v2/players.py— exportget_browser/shutdown_browser(if not already importable)Tests
Acceptance Criteria
Plan reference:
docs/prd-evolution/PHASE0_PROJECT_PLAN.mdWP-03PR #99 opened: #99
Approach: Added
get_browser()/shutdown_browser()as a module-level Playwright singleton inplayers.py. The lifespan hook inmain.pycallsget_browser()on startup (pre-warming Chromium) andshutdown_browser()on exit. The card render block now reuses the singleton browser and closes only the page (infinally) rather than launching and closing a new browser per request.Completed.
lifespan()context manager added toapp/main.py— callsshutdown_browser()on API shutdown for clean Chromium teardown. PR #99 merged via next-release.