Files
Calbook/lib/services/cron.ts

25 lines
699 B
TypeScript

import cron from "node-cron";
import { syncAllEnabledCalendars } from "@/lib/services/caldav";
import { runAppointmentReminders } from "@/lib/services/reminders";
let started = false;
export function startSyncCron() {
if (started || process.env.NODE_ENV === "test") return;
started = true;
cron.schedule("*/5 * * * *", async () => {
try {
await Promise.all([
syncAllEnabledCalendars(),
runAppointmentReminders()
]);
// eslint-disable-next-line no-console
console.log("[calbook] CalDAV Sync ausgeführt");
} catch (error) {
// eslint-disable-next-line no-console
console.error("[calbook] CalDAV Sync Fehler", error);
}
});
}