di-refactor coming along

This commit is contained in:
Boki 2025-06-22 18:14:34 -04:00
parent 7d9044ab29
commit 60ada5f6a3
20 changed files with 582 additions and 335 deletions

View file

@ -1,5 +1,6 @@
import { getLogger } from '@stock-bot/logger';
import { handlerRegistry, type HandlerConfig, type ScheduledJobConfig } from '@stock-bot/queue';
import { handlerRegistry, createJobHandler, type HandlerConfig, type ScheduledJobConfig } from '@stock-bot/queue';
import type { ServiceContainer } from '@stock-bot/di';
import { exchangeOperations } from './operations';
const logger = getLogger('exchanges-handler');
@ -51,8 +52,23 @@ const exchangesHandlerConfig: HandlerConfig = {
},
};
export function initializeExchangesHandler(): void {
export function initializeExchangesHandler(container: ServiceContainer) {
logger.info('Registering exchanges handler...');
handlerRegistry.registerHandler(HANDLER_NAME, exchangesHandlerConfig);
// Update operations to use container
const containerAwareOperations = Object.entries(exchangeOperations).reduce((acc, [key, operation]) => {
acc[key] = createJobHandler(async (payload: any) => {
return operation(payload, container);
});
return acc;
}, {} as Record<string, any>);
const exchangesHandlerConfigWithContainer: HandlerConfig = {
...exchangesHandlerConfig,
operations: containerAwareOperations,
};
handlerRegistry.register(HANDLER_NAME, exchangesHandlerConfigWithContainer);
logger.info('Exchanges handler registered successfully');
}