initial commit
This commit is contained in:
36
instrumentation.ts
Normal file
36
instrumentation.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
Reference in New Issue
Block a user