feat: mail telegram and cron check
This commit is contained in:
1 parent
6e1d0a7568
commit
8b33242db1
6 files changed
+180
No files matched your search
@@ -0,0 +1,35 @@
|
||||
// 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<typeof setInterval> | 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);
|
||||
}
|
||||
Reference in new issue
Block a user