* feat(cadastre): bulk_harvest_quarter Celery task + grid-walker + saga state (#168 PR3/5) Add bulk cadastre harvest pipeline: - services/cadastre/bulk_harvest.py: async harvest_quarter() orchestrator (4 phases) + 7 upsert helpers (parcels/buildings/constructions/oncs/enks/zouit/quarter_stats) using CAST(:x AS jsonb) pattern, begin_nested() SAVEPOINT per grid-walk upsert - services/cadastre/grid_geometry.py: quarter_bbox_3857 (PostGIS ST_Extent) + generate_grid_click_points (15x15 = 225 sub-bbox grid) - workers/tasks/scrape_cadastre.py: bulk_harvest_quarter_task (acks_late=True, dont_autoretry_for NspdBulkWafError), enqueue_cadastre_harvest, cleanup_zombies - api/v1/admin_cadastre.py: 5 endpoints behind AdminTokenAuth — create/list/get/cancel/resume - Tests: 13 service unit + 8 API tests * fixup(cadastre): drop importorskip (PR2 merged) — imports now top-level (#168 PR3) * fixup(cadastre): tile_size unified param + register slow marker (#168 PR3) Blocker #1: rename tile_width/tile_height → tile_size in generate_grid_click_points. Callers in bulk_harvest.py and test_cadastre_bulk.py used tile_size; def had tile_width+tile_height → TypeError at runtime. Blocker #2 (10 failures in test_admin_cadastre.py) was side-effect of #1: TypeError at import chain (app.main → admin_cadastre → bulk_harvest) broke FastAPI app load → dependency_overrides AttributeError. Now resolved. Also register `slow` pytest marker in pyproject.toml to suppress PytestUnknownMarkWarning. * fixup(cadastre): use importlib.util.find_spec instead of import (#168 PR3) Root cause Blocker #2: `import app.workers.tasks.scrape_cadastre` at module top-level REBOUND `app` from FastAPI instance (line 14) to the Python package. All subsequent `app.dependency_overrides[get_db] = ...` failed with AttributeError because `app` was now the namespace module. Fix: probe module availability with importlib.util.find_spec — does not import or rebind names. FastAPI `app` instance stays intact. All 28 cadastre tests pass locally. --------- Co-authored-by: lekss361 <claudestars@proton.me>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
from collections.abc import AsyncIterator
|
|
from contextlib import asynccontextmanager
|
|
|
|
import sentry_sdk
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.v1 import (
|
|
admin_cadastre,
|
|
admin_jobs,
|
|
admin_leads,
|
|
admin_scrape,
|
|
admin_weight_profiles,
|
|
analytics,
|
|
concepts,
|
|
parcels,
|
|
photos,
|
|
)
|
|
from app.core.config import settings
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|
if settings.sentry_dsn:
|
|
sentry_sdk.init(
|
|
dsn=settings.sentry_dsn,
|
|
environment=settings.environment,
|
|
release=settings.sentry_release,
|
|
traces_sample_rate=0.1,
|
|
)
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="GenDesign API", version="0.1.0", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(concepts.router, prefix="/api/v1/concepts", tags=["concepts"])
|
|
app.include_router(parcels.router, prefix="/api/v1/parcels", tags=["parcels"])
|
|
app.include_router(analytics.router, prefix="/api/v1/analytics", tags=["analytics"])
|
|
app.include_router(admin_scrape.router, prefix="/api/v1/admin/scrape", tags=["admin"])
|
|
app.include_router(admin_jobs.router, prefix="/api/v1/admin/jobs", tags=["admin"])
|
|
app.include_router(admin_leads.router, prefix="/api/v1/admin/leads", tags=["admin"])
|
|
app.include_router(
|
|
admin_weight_profiles.router,
|
|
prefix="/api/v1/admin/site-finder/weight-profiles",
|
|
tags=["admin", "site-finder"],
|
|
)
|
|
app.include_router(photos.router, prefix="/api/v1/photos", tags=["photos"])
|
|
app.include_router(
|
|
admin_cadastre.router,
|
|
prefix="/api/v1/admin/cadastre",
|
|
tags=["admin", "cadastre"],
|
|
)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health() -> dict[str, str]:
|
|
return {"status": "ok", "environment": settings.environment}
|