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>
25 lines
1.1 KiB
TypeScript
25 lines
1.1 KiB
TypeScript
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;
|
|
}
|