added env back and fixed up queue service
This commit is contained in:
parent
7f592fe628
commit
d9404c2bda
5 changed files with 258 additions and 33 deletions
|
|
@ -4,7 +4,7 @@
|
|||
import { getLogger } from '@stock-bot/logger';
|
||||
import { loadEnvVariables } from '@stock-bot/config';
|
||||
import { Hono } from 'hono';
|
||||
import { onShutdown, setShutdownTimeout } from '@stock-bot/shutdown';
|
||||
import { Shutdown } from '@stock-bot/shutdown';
|
||||
import { queueManager } from './services/queue.service';
|
||||
import { initializeBatchCache } from './utils/batch-helpers';
|
||||
import { initializeProxyCache } from './providers/proxy.tasks';
|
||||
|
|
@ -24,6 +24,9 @@ const logger = getLogger('data-service');
|
|||
const PORT = parseInt(process.env.DATA_SERVICE_PORT || '3002');
|
||||
let server: any = null;
|
||||
|
||||
// Initialize shutdown manager with 15 second timeout
|
||||
const shutdown = Shutdown.getInstance({ timeout: 15000 });
|
||||
|
||||
// Register all routes
|
||||
app.route('', healthRoutes);
|
||||
app.route('', queueRoutes);
|
||||
|
|
@ -70,26 +73,34 @@ async function startServer() {
|
|||
logger.info(`Data Service started on port ${PORT}`);
|
||||
}
|
||||
|
||||
// Setup shutdown handling
|
||||
setShutdownTimeout(15000);
|
||||
|
||||
// Register cleanup for HTTP server
|
||||
onShutdown(async () => {
|
||||
// Register shutdown handlers
|
||||
shutdown.onShutdown(async () => {
|
||||
if (server) {
|
||||
logger.info('Stopping HTTP server...');
|
||||
server.stop();
|
||||
try {
|
||||
server.stop();
|
||||
logger.info('HTTP server stopped successfully');
|
||||
} catch (error) {
|
||||
logger.error('Error stopping HTTP server', { error });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Register cleanup for queue manager
|
||||
onShutdown(async () => {
|
||||
shutdown.onShutdown(async () => {
|
||||
logger.info('Shutting down queue manager...');
|
||||
await queueManager.shutdown();
|
||||
try {
|
||||
await queueManager.shutdown();
|
||||
logger.info('Queue manager shut down successfully');
|
||||
} catch (error) {
|
||||
logger.error('Error shutting down queue manager', { error });
|
||||
throw error; // Re-throw to mark shutdown as failed
|
||||
}
|
||||
});
|
||||
|
||||
// Start the application
|
||||
startServer().catch(error => {
|
||||
logger.error('Failed to start server', { error });
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
logger.info('Shutdown handlers registered');
|
||||
logger.info('Data service startup initiated with graceful shutdown handlers');
|
||||
Loading…
Add table
Add a link
Reference in a new issue