68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
import http from 'http';
|
|
import { initializeSecrets } from './app'; // Import initialization function
|
|
import app from './app';
|
|
import { initSocket } from './realtime/socket';
|
|
import './queues/tatWorker'; // Initialize TAT worker
|
|
import { logTatConfig } from './config/tat.config';
|
|
import { logSystemConfig } from './config/system.config';
|
|
import { initializeHolidaysCache } from './utils/tatTimeUtils';
|
|
import { seedDefaultConfigurations } from './services/configSeed.service';
|
|
import { startPauseResumeJob } from './jobs/pauseResumeJob';
|
|
import './queues/pauseResumeWorker'; // Initialize pause resume worker
|
|
import { initializeQueueMetrics, stopQueueMetrics } from './utils/queueMetrics';
|
|
|
|
const PORT: number = parseInt(process.env.PORT || '5000', 10);
|
|
|
|
// Start server
|
|
const startServer = async (): Promise<void> => {
|
|
try {
|
|
// Initialize Google Secret Manager before starting server
|
|
// This will merge secrets from GCS into process.env if enabled
|
|
await initializeSecrets();
|
|
|
|
const server = http.createServer(app);
|
|
initSocket(server);
|
|
|
|
// Seed default configurations if table is empty
|
|
try {
|
|
await seedDefaultConfigurations();
|
|
} catch (error) {
|
|
console.error('⚠️ Configuration seeding error:', error);
|
|
}
|
|
|
|
// Initialize holidays cache for TAT calculations
|
|
try {
|
|
await initializeHolidaysCache();
|
|
} catch (error) {
|
|
// Silently fall back to weekends-only TAT calculation
|
|
}
|
|
|
|
// Start scheduled jobs
|
|
startPauseResumeJob();
|
|
|
|
// Initialize queue metrics collection for Prometheus
|
|
initializeQueueMetrics();
|
|
|
|
server.listen(PORT, () => {
|
|
console.log(`🚀 Server running on port ${PORT} | ${process.env.NODE_ENV || 'development'}`);
|
|
});
|
|
} catch (error) {
|
|
console.error('❌ Unable to start server:', error);
|
|
process.exit(1);
|
|
}
|
|
};
|
|
|
|
// Graceful shutdown
|
|
process.on('SIGTERM', () => {
|
|
console.log('🛑 SIGTERM signal received: closing HTTP server');
|
|
stopQueueMetrics();
|
|
process.exit(0);
|
|
});
|
|
|
|
process.on('SIGINT', () => {
|
|
console.log('🛑 SIGINT signal received: closing HTTP server');
|
|
stopQueueMetrics();
|
|
process.exit(0);
|
|
});
|
|
|
|
startServer(); |