Files
MapMil/centers/analytics/api/app/main.py
T
gitrusprusandCursor 1492576fd9 Add Telegram listener, scheduler, and extended parsers admin UI.
Introduce background scheduling and migrations for analytics ingest, expand parser management and map toolbar UX, and ignore local data/session files from version control.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-02 20:47:56 +03:00

45 lines
1.1 KiB
Python

from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .database import Base, engine, get_db
from .routers import admin, internal, map, objects, v1
from .seed import seed_objects, seed_test_consumer
from .services.migrations import migrate_schema
from .services.scheduler import start_scheduler
from .storage import ensure_upload_dir
@asynccontextmanager
async def lifespan(_: FastAPI):
ensure_upload_dir()
Base.metadata.create_all(bind=engine)
migrate_schema(engine)
scheduler_stop = start_scheduler()
db = next(get_db())
try:
seed_objects(db)
seed_test_consumer(db)
finally:
db.close()
yield
scheduler_stop.set()
app = FastAPI(title="CA API (Analytics Center)", lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(objects.router)
app.include_router(map.router)
app.include_router(internal.router)
app.include_router(admin.router)
app.include_router(v1.router)