huge refactor to remove depenencie hell and add typesafe container
This commit is contained in:
parent
28b9822d55
commit
843a7b9b9b
148 changed files with 3603 additions and 2378 deletions
|
|
@ -12,26 +12,34 @@ export function registerCacheServices(
|
|||
const { createServiceCache } = require('@stock-bot/queue');
|
||||
// Get standardized service name from config
|
||||
const serviceName = config.service?.serviceName || config.service?.name || 'unknown';
|
||||
|
||||
|
||||
// Create service-specific cache that uses the service's Redis DB
|
||||
return createServiceCache(serviceName, {
|
||||
host: config.redis.host,
|
||||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
db: config.redis.db, // This will be overridden by ServiceCache
|
||||
}, { logger });
|
||||
return createServiceCache(
|
||||
serviceName,
|
||||
{
|
||||
host: config.redis.host,
|
||||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
db: config.redis.db, // This will be overridden by ServiceCache
|
||||
},
|
||||
{ logger }
|
||||
);
|
||||
}).singleton(),
|
||||
|
||||
|
||||
// Also provide global cache for shared data
|
||||
globalCache: asFunction(({ logger }) => {
|
||||
const { createServiceCache } = require('@stock-bot/queue');
|
||||
const serviceName = config.service?.serviceName || config.service?.name || 'unknown';
|
||||
|
||||
return createServiceCache(serviceName, {
|
||||
host: config.redis.host,
|
||||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
}, { global: true, logger });
|
||||
|
||||
return createServiceCache(
|
||||
serviceName,
|
||||
{
|
||||
host: config.redis.host,
|
||||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
},
|
||||
{ global: true, logger }
|
||||
);
|
||||
}).singleton(),
|
||||
});
|
||||
} else {
|
||||
|
|
@ -40,4 +48,4 @@ export function registerCacheServices(
|
|||
globalCache: asValue(null),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,4 +11,4 @@ export function registerCoreServices(
|
|||
config: asValue(config),
|
||||
logger: asValue(getLogger('di-container')),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { asFunction, asValue, type AwilixContainer } from 'awilix';
|
||||
import { MongoDBClient } from '@stock-bot/mongodb';
|
||||
import { PostgreSQLClient } from '@stock-bot/postgres';
|
||||
import { QuestDBClient } from '@stock-bot/questdb';
|
||||
import { asFunction, asValue, type AwilixContainer } from 'awilix';
|
||||
import type { AppConfig } from '../config/schemas';
|
||||
import type { ServiceDefinitions } from '../container/types';
|
||||
|
||||
|
|
@ -14,7 +14,9 @@ export function registerDatabaseServices(
|
|||
container.register({
|
||||
mongoClient: asFunction(({ logger }) => {
|
||||
// Parse MongoDB URI to extract components
|
||||
const uriMatch = config.mongodb.uri.match(/mongodb:\/\/(?:([^:]+):([^@]+)@)?([^:/]+):(\d+)\/([^?]+)(?:\?authSource=(.+))?/);
|
||||
const uriMatch = config.mongodb.uri.match(
|
||||
/mongodb:\/\/(?:([^:]+):([^@]+)@)?([^:/]+):(\d+)\/([^?]+)(?:\?authSource=(.+))?/
|
||||
);
|
||||
const mongoConfig = {
|
||||
host: uriMatch?.[3] || 'localhost',
|
||||
port: parseInt(uriMatch?.[4] || '27017'),
|
||||
|
|
@ -44,9 +46,9 @@ export function registerDatabaseServices(
|
|||
username: config.postgres.user,
|
||||
password: String(config.postgres.password), // Ensure password is a string
|
||||
};
|
||||
|
||||
logger.debug('PostgreSQL config:', {
|
||||
...pgConfig,
|
||||
|
||||
logger.debug('PostgreSQL config:', {
|
||||
...pgConfig,
|
||||
password: pgConfig.password ? '***' : 'NO_PASSWORD',
|
||||
});
|
||||
return new PostgreSQLClient(pgConfig, logger);
|
||||
|
|
@ -79,4 +81,4 @@ export function registerDatabaseServices(
|
|||
questdbClient: asValue(null),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export { registerCoreServices } from './core.registration';
|
||||
export { registerCacheServices } from './cache.registration';
|
||||
export { registerDatabaseServices } from './database.registration';
|
||||
export { registerApplicationServices } from './service.registration';
|
||||
export { registerCoreServices } from './core.registration';
|
||||
export { registerCacheServices } from './cache.registration';
|
||||
export { registerDatabaseServices } from './database.registration';
|
||||
export { registerApplicationServices } from './service.registration';
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ export function registerApplicationServices(
|
|||
enableMetrics: true,
|
||||
logger,
|
||||
});
|
||||
|
||||
|
||||
const proxyManager = new ProxyManager(proxyCache, config.proxy, logger);
|
||||
|
||||
|
||||
// Note: Initialization will be handled by the lifecycle manager
|
||||
return proxyManager;
|
||||
}).singleton(),
|
||||
|
|
@ -60,7 +60,7 @@ export function registerApplicationServices(
|
|||
// Queue Manager
|
||||
if (config.queue?.enabled && config.redis.enabled) {
|
||||
container.register({
|
||||
queueManager: asFunction(({ logger }) => {
|
||||
queueManager: asFunction(({ logger, handlerRegistry }) => {
|
||||
const { SmartQueueManager } = require('@stock-bot/queue');
|
||||
const queueConfig = {
|
||||
serviceName: config.service?.serviceName || config.service?.name || 'unknown',
|
||||
|
|
@ -79,7 +79,7 @@ export function registerApplicationServices(
|
|||
delayWorkerStart: config.queue!.delayWorkerStart ?? false,
|
||||
autoDiscoverHandlers: true,
|
||||
};
|
||||
return new SmartQueueManager(queueConfig, logger);
|
||||
return new SmartQueueManager(queueConfig, handlerRegistry, logger);
|
||||
}).singleton(),
|
||||
});
|
||||
} else {
|
||||
|
|
@ -87,4 +87,4 @@ export function registerApplicationServices(
|
|||
queueManager: asValue(null),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue