mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 06:15:39 -04:00
Swap the hand-rolled Scheduler class (setInterval-based) for croner, a battle-tested cron library with overlap protection and proper cron expressions. Consolidate lib/jobs/ into a single lib/cron.ts and remove the unused admin jobs API route. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
export async function onRequestError() {
|
|
// Required by Next.js instrumentation
|
|
}
|
|
|
|
export async function register() {
|
|
if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
// Ensure image cache directories exist (all environments)
|
|
const { ensureImageDirs, imageCacheEnabled } = await import(
|
|
"@/lib/services/image-cache"
|
|
);
|
|
if (imageCacheEnabled()) {
|
|
ensureImageDirs();
|
|
}
|
|
|
|
// Run database migrations on startup
|
|
const { runMigrations } = await import("@/lib/db/migrate");
|
|
runMigrations();
|
|
|
|
// Initialize job scheduler
|
|
const { startJobs, stopJobs } = await import("@/lib/cron");
|
|
startJobs();
|
|
|
|
// Graceful shutdown — stop jobs and close DB on container stop
|
|
const { closeDatabase } = await import("@/lib/db/client");
|
|
|
|
const shutdown = () => {
|
|
console.log("[shutdown] Stopping scheduler...");
|
|
stopJobs();
|
|
console.log("[shutdown] Closing database...");
|
|
closeDatabase();
|
|
console.log("[shutdown] Clean shutdown complete");
|
|
process.exit(0);
|
|
};
|
|
|
|
process.on("SIGTERM", shutdown);
|
|
process.on("SIGINT", shutdown);
|
|
}
|
|
}
|