handler to auto register and removed service registry, cleaned up queues and cache naming

This commit is contained in:
Boki 2025-06-23 21:23:38 -04:00
parent 0d1be9e3cb
commit 34c6c36695
19 changed files with 474 additions and 198 deletions

View file

@ -30,10 +30,22 @@ export function registerApplicationServices(
// Proxy Manager
if (config.proxy && config.redis.enabled) {
container.register({
proxyManager: asFunction(({ cache, logger }) => {
if (!cache) {return null;}
proxyManager: asFunction(({ logger }) => {
// Create a separate cache instance for proxy with global prefix
const { createCache } = require('@stock-bot/cache');
const proxyCache = createCache({
redisConfig: {
host: config.redis.host,
port: config.redis.port,
password: config.redis.password,
db: 1, // Use cache DB (usually DB 1)
},
keyPrefix: 'cache:proxy:',
ttl: 86400, // 24 hours default
enableMetrics: true,
logger,
});
const proxyCache = new NamespacedCache(cache, 'proxy');
const proxyManager = new ProxyManager(proxyCache, config.proxy, logger);
// Note: Initialization will be handled by the lifecycle manager

View file

@ -338,6 +338,18 @@ export class ServiceApplication {
let totalScheduledJobs = 0;
for (const [handlerName, config] of allHandlers) {
if (config.scheduledJobs && config.scheduledJobs.length > 0) {
// Check if this handler belongs to the current service
const ownerService = handlerRegistry.getHandlerService(handlerName);
if (ownerService !== this.config.service.serviceName) {
this.logger.trace('Skipping scheduled jobs for handler from different service', {
handler: handlerName,
ownerService,
currentService: this.config.service.serviceName,
});
continue;
}
const queueManager = this.container.resolve('queueManager');
if (!queueManager) {
this.logger.error('Queue manager is not initialized, cannot create scheduled jobs');