[loop-generated] [refactor] Break up lifespan() — 142 lines in app.py #514

Closed
opened 2026-03-19 23:20:00 +00:00 by Timmy · 1 comment
Owner

Problem

lifespan() in src/dashboard/app.py is 142 lines — the longest function in the codebase. It handles startup tasks (DB init, model check, background tasks, SSE setup) and shutdown cleanup.

Suggested refactor

  1. Extract _startup_database() — DB initialization
  2. Extract _startup_background_tasks() — background task spawning
  3. Extract _shutdown_cleanup() — teardown logic
  4. Keep lifespan() as a slim context manager calling the phases

Files

  • src/dashboard/app.py

Acceptance criteria

  • All tests pass
  • lifespan() under 50 lines
  • Each phase helper is independently testable
## Problem `lifespan()` in `src/dashboard/app.py` is 142 lines — the longest function in the codebase. It handles startup tasks (DB init, model check, background tasks, SSE setup) and shutdown cleanup. ## Suggested refactor 1. Extract `_startup_database()` — DB initialization 2. Extract `_startup_background_tasks()` — background task spawning 3. Extract `_shutdown_cleanup()` — teardown logic 4. Keep `lifespan()` as a slim context manager calling the phases ## Files - `src/dashboard/app.py` ## Acceptance criteria - All tests pass - `lifespan()` under 50 lines - Each phase helper is independently testable
Timmy closed this issue 2026-03-19 23:30:33 +00:00
Author
Owner

Previous PR #516 had merge conflicts. Please rebase on latest main and resubmit a clean PR.

Previous PR #516 had merge conflicts. Please rebase on latest main and resubmit a clean PR.
kimi was assigned by Timmy 2026-03-19 23:36:28 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#514