format
This commit is contained in:
parent
d858222af7
commit
7d9044ab29
202 changed files with 10755 additions and 10972 deletions
|
|
@ -4,20 +4,18 @@
|
|||
*/
|
||||
|
||||
// Framework imports
|
||||
import { initializeServiceConfig } from '@stock-bot/config';
|
||||
import { Hono } from 'hono';
|
||||
import { cors } from 'hono/cors';
|
||||
|
||||
import { initializeServiceConfig } from '@stock-bot/config';
|
||||
// Library imports
|
||||
import {
|
||||
createServiceContainer,
|
||||
initializeServices as initializeAwilixServices,
|
||||
type ServiceContainer
|
||||
type ServiceContainer,
|
||||
} from '@stock-bot/di';
|
||||
import { getLogger, setLoggerConfig, shutdownLoggers } from '@stock-bot/logger';
|
||||
import { Shutdown } from '@stock-bot/shutdown';
|
||||
import { handlerRegistry } from '@stock-bot/types';
|
||||
|
||||
// Local imports
|
||||
import { createRoutes } from './routes/create-routes';
|
||||
import { initializeAllHandlers } from './handlers';
|
||||
|
|
@ -84,17 +82,17 @@ async function initializeServices() {
|
|||
ttl: 3600,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
container = createServiceContainer(awilixConfig);
|
||||
await initializeAwilixServices(container);
|
||||
logger.info('Awilix container created and initialized');
|
||||
|
||||
|
||||
// Get the service container for handlers
|
||||
const serviceContainer = container.resolve('serviceContainer');
|
||||
|
||||
|
||||
// Create app with routes
|
||||
app = new Hono();
|
||||
|
||||
|
||||
// Add CORS middleware
|
||||
app.use(
|
||||
'*',
|
||||
|
|
@ -105,17 +103,17 @@ async function initializeServices() {
|
|||
credentials: false,
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
// Create and mount routes using the service container
|
||||
const routes = createRoutes(serviceContainer);
|
||||
app.route('/', routes);
|
||||
|
||||
// Initialize handlers with service container from Awilix
|
||||
logger.debug('Initializing data handlers with Awilix DI pattern...');
|
||||
|
||||
|
||||
// Auto-register all handlers with the service container from Awilix
|
||||
await initializeAllHandlers(serviceContainer);
|
||||
|
||||
|
||||
logger.info('Data handlers initialized with new DI pattern');
|
||||
|
||||
// Create scheduled jobs from registered handlers
|
||||
|
|
@ -175,10 +173,10 @@ async function initializeServices() {
|
|||
logger.info('All services initialized successfully');
|
||||
} catch (error) {
|
||||
console.error('DETAILED ERROR:', error);
|
||||
logger.error('Failed to initialize services', {
|
||||
logger.error('Failed to initialize services', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
details: JSON.stringify(error, null, 2)
|
||||
details: JSON.stringify(error, null, 2),
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -236,14 +234,20 @@ shutdown.onShutdownMedium(async () => {
|
|||
if (container) {
|
||||
// Disconnect database clients
|
||||
const mongoClient = container.resolve('mongoClient');
|
||||
if (mongoClient?.disconnect) await mongoClient.disconnect();
|
||||
|
||||
if (mongoClient?.disconnect) {
|
||||
await mongoClient.disconnect();
|
||||
}
|
||||
|
||||
const postgresClient = container.resolve('postgresClient');
|
||||
if (postgresClient?.disconnect) await postgresClient.disconnect();
|
||||
|
||||
if (postgresClient?.disconnect) {
|
||||
await postgresClient.disconnect();
|
||||
}
|
||||
|
||||
const questdbClient = container.resolve('questdbClient');
|
||||
if (questdbClient?.disconnect) await questdbClient.disconnect();
|
||||
|
||||
if (questdbClient?.disconnect) {
|
||||
await questdbClient.disconnect();
|
||||
}
|
||||
|
||||
logger.info('All services disposed successfully');
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
@ -268,4 +272,4 @@ startServer().catch(error => {
|
|||
process.exit(1);
|
||||
});
|
||||
|
||||
logger.info('Data service startup initiated with improved DI pattern');
|
||||
logger.info('Data service startup initiated with improved DI pattern');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue