work on ib and cleanup
This commit is contained in:
parent
a20a11c1aa
commit
d686a72591
41 changed files with 601 additions and 2793 deletions
|
|
@ -5,6 +5,7 @@ import { Hono } from 'hono';
|
|||
import { Browser } from '@stock-bot/browser';
|
||||
import { loadEnvVariables } from '@stock-bot/config';
|
||||
import { getLogger, shutdownLoggers } from '@stock-bot/logger';
|
||||
import { connectMongoDB, disconnectMongoDB } from '@stock-bot/mongodb-client';
|
||||
import { Shutdown } from '@stock-bot/shutdown';
|
||||
import { initializeIBResources } from './providers/ib.tasks';
|
||||
import { initializeProxyResources } from './providers/proxy.tasks';
|
||||
|
|
@ -18,7 +19,7 @@ loadEnvVariables();
|
|||
const app = new Hono();
|
||||
const logger = getLogger('data-service');
|
||||
const PORT = parseInt(process.env.DATA_SERVICE_PORT || '3002');
|
||||
let server: any = null;
|
||||
let server: ReturnType<typeof Bun.serve> | null = null;
|
||||
|
||||
// Initialize shutdown manager with 15 second timeout
|
||||
const shutdown = Shutdown.getInstance({ timeout: 15000 });
|
||||
|
|
@ -35,6 +36,11 @@ async function initializeServices() {
|
|||
logger.info('Initializing data service...');
|
||||
|
||||
try {
|
||||
// Initialize MongoDB client first
|
||||
logger.info('Starting MongoDB client initialization...');
|
||||
await connectMongoDB();
|
||||
logger.info('MongoDB client initialized');
|
||||
|
||||
// Initialize browser resources
|
||||
logger.info('Starting browser resources initialization...');
|
||||
await Browser.initialize();
|
||||
|
|
@ -122,6 +128,18 @@ shutdown.onShutdown(async () => {
|
|||
}
|
||||
});
|
||||
|
||||
// Add MongoDB shutdown handler
|
||||
shutdown.onShutdown(async () => {
|
||||
logger.info('Shutting down MongoDB client...');
|
||||
try {
|
||||
await disconnectMongoDB();
|
||||
logger.info('MongoDB client shut down successfully');
|
||||
} catch (error) {
|
||||
logger.error('Error shutting down MongoDB client', { error });
|
||||
// Don't throw here to allow other shutdown handlers to complete
|
||||
}
|
||||
});
|
||||
|
||||
// Add logger shutdown handler (should be last)
|
||||
shutdown.onShutdown(async () => {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue