// Ruft die Cron-Route alle 15 Minuten im Production-Prozess auf. // Fehler werden nur geloggt; der nächste Intervall versucht es erneut. let timer: ReturnType | null = null; export function startScheduler(baseUrl: string, intervalMs = 15 * 60 * 1000): () => void { if (timer) return stopScheduler; const secret = process.env.CRON_SECRET ?? ""; const run = async () => { try { const res = await fetch(`${baseUrl}/api/cron/check`, { headers: { "x-cron-secret": secret }, }); if (!res.ok) console.error(`cron check failed: ${res.status}`); } catch (e) { console.error("cron check error", e); } }; void run(); timer = setInterval(() => void run(), intervalMs); return stopScheduler; } export function stopScheduler(): void { if (timer) { clearInterval(timer); timer = null; } } export function ensureSchedulerStarted(): void { if (process.env.NODE_ENV !== "production") return; if (timer) return; const baseUrl = process.env.APP_URL ?? `http://localhost:${process.env.PORT ?? 3000}`; startScheduler(baseUrl); }