cleaner dev experience refactor

This commit is contained in:
Boki 2025-06-22 07:31:00 -04:00
parent 8b17f98845
commit 742e590382
7 changed files with 407 additions and 17 deletions

View file

@ -1,29 +1,74 @@
/**
* Handler auto-registration
* Import all handlers here to trigger auto-registration
* Automatically discovers and registers all handlers
*/
import type { IDataIngestionServices } from '@stock-bot/di';
import { createServiceAdapter } from '@stock-bot/di';
import { QMHandler } from './qm/qm.handler';
import { WebShareHandler } from './webshare/webshare.handler';
import { autoRegisterHandlers } from '@stock-bot/handlers';
import { getLogger } from '@stock-bot/logger';
import { join } from 'path';
// Import handlers for bundling (ensures they're included in the build)
import './qm/qm.handler';
import './webshare/webshare.handler';
// Add more handler imports as needed
const logger = getLogger('handler-init');
/**
* Initialize and register all handlers
* Initialize and register all handlers automatically
*/
export function initializeAllHandlers(services: IDataIngestionServices): void {
export async function initializeAllHandlers(services: IDataIngestionServices): Promise<void> {
// Create generic service container adapter
const serviceContainer = createServiceAdapter(services);
// QM Handler
const qmHandler = new QMHandler(serviceContainer);
qmHandler.register();
try {
// Auto-register all handlers in this directory
const result = await autoRegisterHandlers(
__dirname,
serviceContainer,
{
pattern: '.handler.',
exclude: ['test', 'spec'],
dryRun: false
}
);
logger.info('Handler auto-registration complete', {
registered: result.registered,
failed: result.failed
});
if (result.failed.length > 0) {
logger.error('Some handlers failed to register', { failed: result.failed });
}
} catch (error) {
logger.error('Handler auto-registration failed', { error });
// Fall back to manual registration
await manualHandlerRegistration(serviceContainer);
}
}
/**
* Manual fallback registration
*/
async function manualHandlerRegistration(serviceContainer: any): Promise<void> {
logger.warn('Falling back to manual handler registration');
// WebShare Handler
const webShareHandler = new WebShareHandler(serviceContainer);
webShareHandler.register();
// TODO: Add other handlers here as they're converted
// const ibHandler = new IBHandler(serviceContainer);
// ibHandler.register();
try {
// Import and register handlers manually
const { QMHandler } = await import('./qm/qm.handler');
const qmHandler = new QMHandler(serviceContainer);
qmHandler.register();
const { WebShareHandler } = await import('./webshare/webshare.handler');
const webShareHandler = new WebShareHandler(serviceContainer);
webShareHandler.register();
logger.info('Manual handler registration complete');
} catch (error) {
logger.error('Manual handler registration failed', { error });
throw error;
}
}