// In-container replacement for Vercel Cron (see vercel.json's old schedule). // Runs alongside `node server.js` in the Docker image — see Dockerfile. import "dotenv/config"; const PORT = process.env.PORT || 3000; const BASE = `http://127.0.0.1:${PORT}`; const SECRET = process.env.CRON_SECRET; if (!SECRET) { console.error("[cron] CRON_SECRET not set — scheduler exiting"); process.exit(1); } // Schedules match the original vercel.json (UTC — containers default to UTC). const JOBS = [ { path: "/api/cron/insights-snapshot", match: (d) => d.getUTCHours() === 2 && d.getUTCMinutes() === 0 }, { path: "/api/cron/reconcile-scheduled", match: (d) => d.getUTCHours() === 3 && d.getUTCMinutes() === 0 }, { path: "/api/cron/token-health", match: (d) => d.getUTCHours() === 3 && d.getUTCMinutes() === 30 }, { path: "/api/cron/ig-publisher", match: (d) => d.getUTCMinutes() % 10 === 0 }, ]; async function run(jobPath) { try { const res = await fetch(`${BASE}${jobPath}`, { headers: { authorization: `Bearer ${SECRET}` } }); console.log(`[cron] ${jobPath} -> ${res.status}`); } catch (e) { console.error(`[cron] ${jobPath} failed:`, e?.message ?? e); } } setInterval(() => { const now = new Date(); for (const job of JOBS) if (job.match(now)) run(job.path); }, 60_000); console.log("[cron] scheduler started");