import { materializeSchedules } from "./maintenanceSchedules.js"; // Windows are made a week ahead, so a pass is only needed now and then: to make the next day's, and to pick up a server added to a // schedule's list. Quarter-hourly keeps a restart from leaving a gap. const INTERVAL_MS = 15 * 60 * 1000; const FIRST_PASS_DELAY_MS = 30 * 1000; let timer: ReturnType | null = null; async function pass(): Promise { try { const made = await materializeSchedules(); if (made > 0) console.log(`[maintenanceSchedules] made ${made} maintenance window${made === 1 ? "" : "s"} from recurring schedules`); } catch (err) { console.error("[maintenanceSchedules]", err instanceof Error ? err.message : err); } } export async function initMaintenanceScheduleScheduler(): Promise { if (timer) return; timer = setInterval(() => void pass(), INTERVAL_MS); setTimeout(() => void pass(), FIRST_PASS_DELAY_MS); console.log(`[maintenanceSchedules] making windows from recurring schedules a week ahead, checked every ${INTERVAL_MS / 60000} minutes`); }