import { enqueueJob } from "@/server/jobs/queues"; import { geocodingProviderName } from "@/server/services/geo/config"; /** * Ask the worker to geocode a site (after create / address change / import confirmation). * Never runs inline: no external request inside a user request (OSM policy: no bulk geocoding in * requests). If the queue is not reachable yet (lazy Redis connection) one delayed retry is made; * otherwise the site stays without coordinates ("ohne Ortsangabe") until the next change or * `scripts/geocode-backfill.ts`. Never throws. */ export async function requestSiteGeocoding(tenantId: string, siteId: string): Promise { if (geocodingProviderName() === "none") return false; const payload = { tenantId, entityId: siteId }; try { if (await enqueueJob("geocode-site", payload)) return true; } catch (err) { console.error("[geo] enqueue geocode-site failed:", (err as Error).message); } const timer = setTimeout(() => { enqueueJob("geocode-site", payload).catch(() => undefined); }, 1_500); timer.unref?.(); return false; }