mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-02-13 16:15:43 +01:00
- Update tsconfig to ES2024 target and bundler moduleResolution - Add dynamic imports for chart.js and recharts (bundle optimization) - Consolidate 17 useState into useReducer in sessions page - Fix 18 .js extension imports across lib files - Add type declarations for @rapideditor/country-coder - Fix platform user types (PlatformUserRole enum) - Fix Calendar component prop types - Centralize next-auth type augmentation - Add force-dynamic to all API routes (prevent build-time prerender) - Fix Prisma JSON null handling with Prisma.DbNull - Fix various type mismatches (SessionMessage, ImportRecord, etc.) - Export ButtonProps from button component - Update next-themes import path - Replace JSX.Element with React.ReactElement - Remove obsolete debug scripts and pnpm lockfile - Downgrade eslint to v8 for next compatibility
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
// Combined scheduler initialization with graceful shutdown
|
|
|
|
import { prisma } from "./prisma";
|
|
import { startProcessingScheduler } from "./processingScheduler";
|
|
import { startCsvImportScheduler } from "./scheduler";
|
|
|
|
/**
|
|
* Initialize all schedulers
|
|
* - CSV import scheduler (runs every 15 minutes)
|
|
* - Session processing scheduler (runs every hour)
|
|
*/
|
|
export function initializeSchedulers() {
|
|
// Start the CSV import scheduler
|
|
startCsvImportScheduler();
|
|
|
|
// Start the session processing scheduler
|
|
startProcessingScheduler();
|
|
|
|
console.log("All schedulers initialized successfully");
|
|
|
|
// Set up graceful shutdown for schedulers
|
|
setupGracefulShutdown();
|
|
}
|
|
|
|
/**
|
|
* Set up graceful shutdown handling for schedulers and database connections
|
|
*/
|
|
function setupGracefulShutdown() {
|
|
const shutdown = async (signal: string) => {
|
|
console.log(`\nReceived ${signal}. Starting graceful shutdown...`);
|
|
|
|
try {
|
|
// Disconnect from database
|
|
await prisma.$disconnect();
|
|
console.log("Database connections closed.");
|
|
|
|
// Exit the process
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error("Error during shutdown:", error);
|
|
process.exit(1);
|
|
}
|
|
};
|
|
|
|
// Handle various termination signals
|
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
process.on("SIGUSR2", () => shutdown("SIGUSR2")); // Nodemon restart
|
|
|
|
// Handle uncaught exceptions
|
|
process.on("uncaughtException", (error) => {
|
|
console.error("Uncaught Exception:", error);
|
|
shutdown("uncaughtException");
|
|
});
|
|
|
|
process.on("unhandledRejection", (reason, promise) => {
|
|
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
shutdown("unhandledRejection");
|
|
});
|
|
}
|