L13 Planung: Geocoding der Objekte über OpenStreetMap Nominatim
Provider-Interface (nominatim|none), strukturierte Suche mit User-Agent und Accept-Language, Drosselung 1/s je Prozess, Job geocode-site (Worker: Concurrency 1 + Limiter), Cache am Objekt, manuelle Koordinaten bleiben, Auslöser Anlage/Adressänderung/Import-Bestätigung nur per Queue, Backfill-Skript, Env-Beispiele. Tests mit Fake-Provider, Nominatim nie aufgerufen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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<boolean> {
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user