refactor(#101): extract backfill-age routes to backfill_routes.py - #200
Merged
Conversation
Move POST /backfill-age + GET /backfill-age/status out of main.py into a new backfill_routes.py APIRouter, along with their shared run-state (_backfill_state / _backfill_lock — private to these handlers, no other call site) and the _backfill_unprocessed_breakdown query helper. Follows the proven #101 slice-#3 (search_routes.py) pattern: - handlers resolve main-owned symbols (_check_auth, _check_viz_auth, _mp) via lazy `import main` at request time, so test patches on those names stay effective and the suite is unmodified; - BackfillAgeBody (search_models) and record_db_error (db_errors) are imported directly — neither imports main, so no circular import; - main.py mounts via app.include_router and re-exports the pure _backfill_unprocessed_breakdown so tests/test_backfill_unprocessed.py keeps resolving main._backfill_unprocessed_breakdown unchanged. Pure refactor, behavior identical. main.py 3116 -> 2907 lines (-209). Full suite: 603 passed, 1 skipped, 20 subtests — same as baseline. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extracts the AGE-backfill route cluster out of
main.pyinto a newbackfill_routes.py— the next clean slice for #101.POST /backfill-agemain.pybackfill_routes.py(APIRouter)GET /backfill-age/statusmain.pybackfill_routes.py(APIRouter)_backfill_state/_backfill_lockmain.pymodule statebackfill_routes.py(private to these handlers — no other call site)_backfill_unprocessed_breakdownmain.pybackfill_routes.py(re-exported by main for tests)main.py: 3116 → 2907 lines (−209). New module is 270 lines.
How (same pattern as slice #3 /
search_routes.py)_check_auth,_check_viz_auth,_mp) via lazyimport mainat request time, so the test suite's patches on those names stay effective and tests are unmodified.BackfillAgeBody(fromsearch_models) andrecord_db_error(fromdb_errors) are imported directly — neither importsmain, so no circular import (search_routes.pyimportssearch_modelsthe same way)._backfill_state/_backfill_lockmove outright (grep confirmed no othermain.pycall site). They're shared by reference within the module and never rebound, so mutation semantics are identical.main.pymounts viaapp.include_router(_backfill_router)and re-exports the pure_backfill_unprocessed_breakdownsotests/test_backfill_unprocessed.pykeeps resolvingmain._backfill_unprocessed_breakdownunchanged.Behavior
Pure refactor — no logic change. The only non-mechanical edit is lifting the function-local
import logginginbackfill_age_status's except clause to a module-level import.Verification
app;main._backfill_unprocessed_breakdown is backfill_routes._backfill_unprocessed_breakdown.main.py(BackfillAgeBody/Bodywere backfill-only and removed;record_db_errorstill used 5× elsewhere, kept).py_compile+ the test suite.Refactor only — not deployed to familiar (deploy is separate).
🤖 Generated with Claude Code