integrated data-ingestion
This commit is contained in:
parent
9673ae70ef
commit
3227388d25
15 changed files with 226 additions and 133 deletions
|
|
@ -7,7 +7,8 @@ import { getLogger, setLoggerConfig, shutdownLoggers } from '@stock-bot/logger';
|
|||
import type { QueueManager } from '@stock-bot/queue';
|
||||
import { Shutdown } from '@stock-bot/shutdown';
|
||||
import { ProxyManager } from '@stock-bot/utils';
|
||||
import type { ServiceContainer } from '@stock-bot/di';
|
||||
import { ServiceContainer, ConnectionFactory } from '@stock-bot/di';
|
||||
import { handlerRegistry } from '@stock-bot/handlers';
|
||||
// Local imports
|
||||
import { setupServiceContainer } from './setup/database-setup';
|
||||
import { createRoutes } from './routes/create-routes';
|
||||
|
|
@ -15,8 +16,7 @@ import { createRoutes } from './routes/create-routes';
|
|||
const config = initializeServiceConfig();
|
||||
console.log('Data Service Configuration:', JSON.stringify(config, null, 2));
|
||||
const serviceConfig = config.service;
|
||||
const databaseConfig = config.database;
|
||||
const queueConfig = config.queue;
|
||||
// Configuration will be passed to service container setup
|
||||
|
||||
if (config.log) {
|
||||
setLoggerConfig({
|
||||
|
|
@ -34,6 +34,7 @@ const logger = getLogger('data-ingestion');
|
|||
const PORT = serviceConfig.port;
|
||||
let server: ReturnType<typeof Bun.serve> | null = null;
|
||||
let serviceContainer: ServiceContainer | null = null;
|
||||
let connectionFactory: ConnectionFactory | null = null;
|
||||
let queueManager: QueueManager | null = null;
|
||||
let app: Hono | null = null;
|
||||
|
||||
|
|
@ -47,7 +48,9 @@ async function initializeServices() {
|
|||
try {
|
||||
// Initialize service container with connection pools
|
||||
logger.debug('Setting up service container with connection pools...');
|
||||
serviceContainer = await setupServiceContainer();
|
||||
const { container, factory } = await setupServiceContainer();
|
||||
serviceContainer = container;
|
||||
connectionFactory = factory;
|
||||
logger.info('Service container initialized with connection pools');
|
||||
|
||||
// Create app with routes that have access to the container
|
||||
|
|
@ -78,7 +81,7 @@ async function initializeServices() {
|
|||
await ProxyManager.initialize();
|
||||
logger.info('Proxy manager initialized');
|
||||
|
||||
// Initialize handlers (register handlers and scheduled jobs)
|
||||
// Initialize handlers using the handler registry
|
||||
logger.debug('Initializing data handlers...');
|
||||
const { initializeWebShareProvider } = await import('./handlers/webshare/webshare.handler');
|
||||
const { initializeIBProvider } = await import('./handlers/ib/ib.handler');
|
||||
|
|
@ -92,10 +95,22 @@ async function initializeServices() {
|
|||
initializeQMProvider(serviceContainer);
|
||||
|
||||
logger.info('Data handlers initialized with service container');
|
||||
|
||||
// Register handlers with queue system
|
||||
logger.debug('Registering handlers with queue system...');
|
||||
try {
|
||||
await queueManager.registerHandlers(handlerRegistry.getAllHandlers());
|
||||
logger.info('Handlers registered with queue system');
|
||||
} catch (error) {
|
||||
logger.error('Failed to register handlers with queue system', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Create scheduled jobs from registered handlers
|
||||
logger.debug('Creating scheduled jobs from registered handlers...');
|
||||
const { handlerRegistry } = await import('@stock-bot/queue');
|
||||
const allHandlers = handlerRegistry.getAllHandlers();
|
||||
|
||||
let totalScheduledJobs = 0;
|
||||
|
|
@ -146,7 +161,10 @@ async function initializeServices() {
|
|||
|
||||
logger.info('All services initialized successfully');
|
||||
} catch (error) {
|
||||
logger.error('Failed to initialize services', { error });
|
||||
logger.error('Failed to initialize services', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -199,9 +217,13 @@ shutdown.onShutdownHigh(async () => {
|
|||
shutdown.onShutdownMedium(async () => {
|
||||
logger.info('Disposing service container and connections...');
|
||||
try {
|
||||
if (connectionFactory) {
|
||||
await connectionFactory.disposeAll();
|
||||
logger.info('Connection factory disposed, all pools closed');
|
||||
}
|
||||
if (serviceContainer) {
|
||||
await serviceContainer.dispose();
|
||||
logger.info('Service container disposed, all connections closed');
|
||||
logger.info('Service container disposed');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Error disposing service container', { error });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue