port-nimara-client-portal/server/plugins/startup-health.ts

31 lines
1.0 KiB
TypeScript

import { healthChecker } from '../utils/health-checker';
export default defineNitroPlugin(async (nitroApp) => {
console.log('[Startup Health] Initializing application health checks...');
// Perform initial health checks on startup
const startTime = Date.now();
try {
const isReady = await healthChecker.performStartupHealthChecks();
if (isReady) {
console.log(`[Startup Health] Application ready in ${Date.now() - startTime}ms`);
} else {
console.warn('[Startup Health] Application started but some services are unavailable');
console.warn('[Startup Health] Status:', healthChecker.getStartupStatus());
}
} catch (error) {
console.error('[Startup Health] Failed to perform startup checks:', error);
}
// Monitor service health periodically
setInterval(async () => {
try {
await healthChecker.performStartupHealthChecks();
} catch (error) {
console.error('[Startup Health] Periodic health check failed:', error);
}
}, 60000); // Check every minute
});