fix(adsb): keep aircraft ingest alive with no browser viewport
The ADSB refresh loop only persisted positions for registered WS viewports, so aircraft_positions went silent for a day whenever nobody had the map open (max(ts) frozen at 2026-11-20 04:58 while USGS/news ingest kept running). When no client viewport is registered the loop now sweeps the chokepoint presets (ADSB_WATCH_ENABLED=1, ADSB_WATCH_INTERVAL=30s, 5 boxes ~65-81 nm) through the same fetch_aircraft(persist=True) path, so the hypertable and aircraft_tracks_1min keep advancing unattended. Viewport polling keeps its 8 s cadence when a tab is connected.
This commit is contained in:
parent
915f6cbe25
commit
366ee12b46
3 changed files with 108 additions and 2 deletions
|
|
@ -107,3 +107,12 @@ VESSELAPI_MAX_CALLS_PER_DAY = int(os.getenv("VESSELAPI_MAX_CALLS_PER_DAY", "5"))
|
|||
# Run the VesselAPI poller inside the dashboard process (default on, like AIS).
|
||||
VESSELAPI_IN_APP = os.getenv("VESSELAPI_IN_APP", "1").lower() in ("1", "true", "yes")
|
||||
VESSELAPI_IN_INGEST = os.getenv("VESSELAPI_IN_INGEST", "0").lower() in ("1", "true", "yes")
|
||||
|
||||
# ADS-B (ADSB.lol, no key). The dashboard's refresh loop follows browser
|
||||
# viewports; with no tab open it persisted nothing and aircraft_positions went
|
||||
# silent for a day. ADSB_WATCH_ENABLED=1 makes the loop sweep the chokepoint
|
||||
# presets while idle, so the hypertable keeps advancing unattended.
|
||||
ADSB_REFRESH_INTERVAL = float(os.getenv("ADSB_REFRESH_INTERVAL", "8"))
|
||||
ADSB_WATCH_ENABLED = os.getenv("ADSB_WATCH_ENABLED", "1").lower() in ("1", "true", "yes")
|
||||
# Idle sweep cadence; 30 s over 5 preset boxes ≈ 0.17 req/s to ADSB.lol.
|
||||
ADSB_WATCH_INTERVAL = float(os.getenv("ADSB_WATCH_INTERVAL", "30"))
|
||||
|
|
|
|||
39
app/main.py
39
app/main.py
|
|
@ -126,14 +126,49 @@ app.include_router(auth_router)
|
|||
STATIC_DIR = Path(__file__).parent / "static"
|
||||
|
||||
|
||||
def _adsb_watch_boxes() -> list[tuple[float, float, float, float]]:
|
||||
"""Chokepoint presets as viewport boxes (minlon, minlat, maxlon, maxlat).
|
||||
|
||||
Used only while no browser viewport is registered: without it the refresh
|
||||
loop persists nothing and ``aircraft_positions`` silently stalls whenever
|
||||
nobody has the map open.
|
||||
"""
|
||||
from chokepoints import chokepoints
|
||||
|
||||
out: list[tuple[float, float, float, float]] = []
|
||||
for preset in chokepoints():
|
||||
try:
|
||||
# Preset bboxes are minlat,minlon,maxlat,maxlon (VesselAPI order).
|
||||
minlat, minlon, maxlat, maxlon = (float(v) for v in str(preset["bbox"]).split(","))
|
||||
except (KeyError, TypeError, ValueError):
|
||||
continue
|
||||
out.append((minlon, minlat, maxlon, maxlat))
|
||||
return out
|
||||
|
||||
|
||||
async def _adsb_refresh_loop() -> None:
|
||||
"""Poll ADSB.lol for connected viewports — never from GET /api/aircraft."""
|
||||
"""Poll ADSB.lol for connected viewports — never from GET /api/aircraft.
|
||||
|
||||
When no client viewport is registered the loop sweeps the watch boxes
|
||||
(chokepoint presets) at ``ADSB_WATCH_INTERVAL`` so aircraft ingest keeps
|
||||
advancing with no map open.
|
||||
"""
|
||||
from ws_manager import manager
|
||||
from live_layers import fetch_aircraft
|
||||
from config import ADSB_REFRESH_INTERVAL, ADSB_WATCH_ENABLED, ADSB_WATCH_INTERVAL
|
||||
|
||||
watch_boxes: list[tuple[float, float, float, float]] | None = None
|
||||
|
||||
while True:
|
||||
interval = ADSB_REFRESH_INTERVAL
|
||||
try:
|
||||
boxes = manager.viewports()
|
||||
if not boxes and ADSB_WATCH_ENABLED:
|
||||
if watch_boxes is None:
|
||||
watch_boxes = _adsb_watch_boxes()
|
||||
boxes = watch_boxes
|
||||
interval = ADSB_WATCH_INTERVAL
|
||||
logger.debug("adsb_idle_watch", boxes=len(boxes))
|
||||
for box in boxes:
|
||||
bbox = f"{box[0]},{box[1]},{box[2]},{box[3]}"
|
||||
try:
|
||||
|
|
@ -142,7 +177,7 @@ async def _adsb_refresh_loop() -> None:
|
|||
logger.warning("adsb_refresh_failed", error=str(exc))
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.warning("adsb_refresh_loop", error=str(exc))
|
||||
await asyncio.sleep(8)
|
||||
await asyncio.sleep(interval)
|
||||
|
||||
|
||||
class CachedStaticFiles(StaticFiles):
|
||||
|
|
|
|||
Loading…
Reference in a new issue