Files
NeoCom/instrumentation.ts
2026-04-09 20:36:10 -07:00

37 lines
1.2 KiB
TypeScript

/**
* Next.js Instrumentation Hook
*
* https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation
*
* This file is automatically loaded by Next.js when the server starts.
* We use it to boot the EVE auto-sync cron job in the Node.js runtime.
*
* IMPORTANT: We only run on the server (Node.js runtime), not on the
* Edge runtime — node-cron requires Node.js APIs.
*/
export async function register() {
// Only boot in the Node.js runtime — not Edge, not Workers
if (process.env.NEXT_RUNTIME !== "nodejs") {
return;
}
// Skip during builds (Next.js runs instrumentation during `next build` too)
if (process.env.NEXT_PHASE === "phase-production-build") {
return;
}
console.log("[instrumentation] Booting EVE auto-sync cron...");
// Dynamic import keeps node-cron out of the Edge bundle
const { startAutoSyncCron } = await import("@/lib/eve/cron");
// Default: tick every minute. Override with EVE_SYNC_CRON env var.
// Examples:
// "* * * * *" — every minute (default)
// "*/30 * * * * *" — every 30 seconds (uses 6-field syntax)
// "*/5 * * * *" — every 5 minutes
const schedule = process.env.EVE_SYNC_CRON || "* * * * *";
startAutoSyncCron(schedule);
}