mirror of
https://github.com/azaion/gps-denied-onboard.git
synced 2026-06-23 18:21:13 +00:00
feat(01-08): rewire app.py lifespan and deps.py to use build_pipeline
- app.py: replace inline component wiring with build_pipeline(env=cfg.env) - Store processor as app.state.processor (and backwards-compat pipeline_components) - RuntimeConfig replaces get_settings(); MAVLink stop() on shutdown - deps.py: get_flight_processor prefers app.state.processor from lifespan - Falls back to build_pipeline() for test contexts without lifespan - Per-request repo/streamer swap preserved
This commit is contained in:
@@ -5,7 +5,7 @@ from fastapi import Depends, HTTPException, Request
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from gps_denied.config import get_settings
|
||||
from gps_denied.config import RuntimeConfig, get_settings
|
||||
from gps_denied.core.processor import FlightProcessor
|
||||
from gps_denied.core.sse import SSEEventStreamer
|
||||
from gps_denied.db.engine import get_session
|
||||
@@ -65,14 +65,23 @@ async def get_flight_processor(
|
||||
) -> FlightProcessor:
|
||||
global _processor
|
||||
if _processor is None:
|
||||
eskf_config = getattr(request.app.state, "eskf_config", None)
|
||||
_processor = FlightProcessor(repo, sse, eskf_config=eskf_config)
|
||||
# Підключаємо pipeline компоненти з lifespan
|
||||
components = getattr(request.app.state, "pipeline_components", None)
|
||||
if components:
|
||||
_processor.attach_components(**components)
|
||||
# Оновлюємо repo (нова сесія на кожен запит)
|
||||
# Prefer the processor already built by lifespan (via build_pipeline)
|
||||
lifespan_processor = getattr(request.app.state, "processor", None)
|
||||
if lifespan_processor is not None:
|
||||
_processor = lifespan_processor
|
||||
else:
|
||||
# Fallback: build pipeline directly (e.g. in tests without lifespan)
|
||||
from gps_denied.pipeline import build_pipeline
|
||||
_settings = RuntimeConfig()
|
||||
_processor = build_pipeline(
|
||||
env=_settings.env,
|
||||
config=_settings,
|
||||
repository=repo,
|
||||
streamer=sse,
|
||||
)
|
||||
# Оновлюємо repo та streamer (нова сесія на кожен запит)
|
||||
_processor.repository = repo
|
||||
_processor.streamer = sse
|
||||
return _processor
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user