huge refactor done

This commit is contained in:
Boki 2025-06-24 11:59:35 -04:00
parent 843a7b9b9b
commit 60d7de1da8
16 changed files with 472 additions and 443 deletions

View file

@ -278,7 +278,11 @@ export class ServiceApplication {
// Initialize handlers if enabled
if (this.serviceConfig.enableHandlers && handlerInitializer) {
this.logger.debug('Initializing handlers...');
await handlerInitializer(this.serviceContainer);
// Pass the service container with the DI container attached
const containerWithDI = Object.assign({}, this.serviceContainer, {
_diContainer: this.container
});
await handlerInitializer(containerWithDI);
this.logger.info('Handlers initialized');
}
@ -335,6 +339,8 @@ export class ServiceApplication {
this.logger.debug('Creating scheduled jobs from registered handlers...');
const handlerRegistry = this.container.resolve<HandlerRegistry>('handlerRegistry');
const allHandlers = handlerRegistry.getAllHandlersWithSchedule();
this.logger.info(`Found ${allHandlers.size} handlers with scheduled jobs: ${Array.from(allHandlers.keys()).join(', ')}`);
let totalScheduledJobs = 0;
for (const [handlerName, config] of allHandlers) {
@ -356,7 +362,16 @@ export class ServiceApplication {
this.logger.error('Queue manager is not initialized, cannot create scheduled jobs');
continue;
}
const queue = queueManager.getQueue(handlerName);
// Pass the handler registry explicitly when creating queues for scheduled jobs
this.logger.debug('Creating queue for scheduled jobs', {
handlerName,
hasHandlerRegistry: !!handlerRegistry,
registeredHandlers: handlerRegistry.getHandlerNames(),
});
const queue = queueManager.getQueue(handlerName, {
handlerRegistry: handlerRegistry
});
for (const scheduledJob of config.scheduledJobs) {
// Include handler and operation info in job data
@ -375,6 +390,12 @@ export class ServiceApplication {
},
};
this.logger.debug('Adding scheduled job', {
handler: handlerName,
operation: scheduledJob.operation,
hasOperation: !!handlerRegistry.getOperation(handlerName, scheduledJob.operation),
});
await queue.addScheduledJob(
scheduledJob.operation,
jobData,