OSM: asyncio.create_task statt BackgroundTasks — Hintergrund-Fetch funktioniert jetzt

BackgroundTasks wurde nicht ausgeführt (Bug in der Starlette-Integration).
asyncio.create_task() plant den Overpass-Fetch direkt im Event-Loop ein,
Argumente explizit übergeben statt Closure um Capture-Probleme zu vermeiden.
This commit is contained in:
rene 2026-04-25 22:22:39 +02:00
parent 8cc528350d
commit ddff1d3571

View file

@ -167,7 +167,6 @@ async def get_pois(
north: float = Query(...), north: float = Query(...),
east: float = Query(...), east: float = Query(...),
fast: bool = Query(False), fast: bool = Query(False),
background_tasks: BackgroundTasks = None,
user = Depends(get_optional_user), user = Depends(get_optional_user),
): ):
result = [] result = []
@ -178,11 +177,11 @@ async def get_pois(
stale = _stale_tiles(type, tiles) stale = _stale_tiles(type, tiles)
if stale and not fast: if stale and not fast:
# Hintergrund-Fetch: Antwort kommt sofort, Overpass lädt asynchron # Direkt in den Event-Loop einplanen — Antwort kommt sofort zurück
async def _bg_fetch(): async def _bg_fetch(poi_type, stale_tiles):
for (x, y) in stale: for (x, y) in stale_tiles:
await _fetch_and_store_tile(type, x, y) await _fetch_and_store_tile(poi_type, x, y)
background_tasks.add_task(_bg_fetch) asyncio.create_task(_bg_fetch(type, stale))
with db() as conn: with db() as conn:
reported = { reported = {