updated di
This commit is contained in:
parent
3227388d25
commit
c5a114d544
9 changed files with 545 additions and 306 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import {
|
||||
ScheduledHandler,
|
||||
BaseHandler,
|
||||
Handler,
|
||||
Operation,
|
||||
QueueSchedule,
|
||||
|
|
@ -8,13 +8,13 @@ import {
|
|||
type ExecutionContext,
|
||||
type HandlerConfigWithSchedule
|
||||
} from '@stock-bot/handlers';
|
||||
import type { ServiceContainer } from '@stock-bot/di';
|
||||
import type { IDataIngestionServices, IExecutionContext } from '@stock-bot/di';
|
||||
import type { SymbolSpiderJob } from './shared/types';
|
||||
|
||||
@Handler('qm')
|
||||
export class QMHandler extends ScheduledHandler {
|
||||
constructor(container: ServiceContainer) {
|
||||
super(container);
|
||||
export class QMHandler extends BaseHandler {
|
||||
constructor(services: IDataIngestionServices) {
|
||||
super(services);
|
||||
}
|
||||
|
||||
async execute(operation: string, input: unknown, context: ExecutionContext): Promise<unknown> {
|
||||
|
|
@ -37,17 +37,32 @@ export class QMHandler extends ScheduledHandler {
|
|||
description: 'Create and maintain QM sessions'
|
||||
})
|
||||
async createSessions(input: unknown, context: ExecutionContext): Promise<unknown> {
|
||||
const { createSessions } = await import('./operations/session.operations');
|
||||
await createSessions(context.serviceContainer);
|
||||
return { success: true, message: 'QM sessions created successfully' };
|
||||
// Direct access to typed dependencies
|
||||
const sessionsCollection = this.mongodb.collection('qm_sessions');
|
||||
|
||||
// Get existing sessions
|
||||
const existingSessions = await sessionsCollection.find({}).toArray();
|
||||
this.logger.info('Found existing QM sessions', { count: existingSessions.length });
|
||||
|
||||
// Cache session count for monitoring
|
||||
await this.cache.set('qm-sessions-count', existingSessions.length, 3600);
|
||||
|
||||
return { success: true, existingCount: existingSessions.length };
|
||||
}
|
||||
|
||||
@Operation('search-symbols')
|
||||
async searchSymbols(input: unknown, context: ExecutionContext): Promise<unknown> {
|
||||
const { fetchSymbols } = await import('./operations/symbols.operations');
|
||||
const symbols = await fetchSymbols(context.serviceContainer);
|
||||
|
||||
// Direct access to typed dependencies
|
||||
const symbolsCollection = this.mongodb.collection('qm_symbols');
|
||||
|
||||
// Get symbols from database
|
||||
const symbols = await symbolsCollection.find({}).limit(100).toArray();
|
||||
this.logger.info('QM symbol search completed', { count: symbols.length });
|
||||
|
||||
if (symbols && symbols.length > 0) {
|
||||
// Cache result for performance
|
||||
await this.cache.set('qm-symbols-sample', symbols.slice(0, 10), 1800);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'QM symbol search completed successfully',
|
||||
|
|
@ -70,40 +85,51 @@ export class QMHandler extends ScheduledHandler {
|
|||
description: 'Comprehensive symbol search using QM API'
|
||||
})
|
||||
async spiderSymbolSearch(payload: SymbolSpiderJob, context: ExecutionContext): Promise<unknown> {
|
||||
const { spiderSymbolSearch } = await import('./operations/spider.operations');
|
||||
return await spiderSymbolSearch(payload, context.serviceContainer);
|
||||
this.logger.info('Starting QM spider symbol search', { payload });
|
||||
|
||||
// Direct access to typed dependencies
|
||||
const spiderCollection = this.mongodb.collection('qm_spider_results');
|
||||
|
||||
// Store spider job info
|
||||
const spiderResult = {
|
||||
payload,
|
||||
startTime: new Date(),
|
||||
status: 'started'
|
||||
};
|
||||
|
||||
await spiderCollection.insertOne(spiderResult);
|
||||
|
||||
// Schedule follow-up processing if needed
|
||||
await this.scheduleOperation('search-symbols', { source: 'spider' }, 5000);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'QM spider search initiated',
|
||||
spiderJobId: spiderResult._id
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize and register the QM provider
|
||||
export function initializeQMProvider(container: ServiceContainer) {
|
||||
// Create handler instance
|
||||
const handler = new QMHandler(container);
|
||||
// Initialize and register the QM provider with new DI pattern
|
||||
export function initializeQMProviderNew(services: IDataIngestionServices) {
|
||||
// Create handler instance with new DI
|
||||
const handler = new QMHandler(services);
|
||||
|
||||
// Register with legacy format for now
|
||||
// Register with legacy format for backward compatibility
|
||||
const qmProviderConfig: HandlerConfigWithSchedule = {
|
||||
name: 'qm',
|
||||
operations: {
|
||||
'create-sessions': createJobHandler(async (payload) => {
|
||||
return await handler.execute('create-sessions', payload, {
|
||||
type: 'queue',
|
||||
serviceContainer: container,
|
||||
metadata: { source: 'queue', timestamp: Date.now() }
|
||||
});
|
||||
const context = handler.createExecutionContext('queue', { source: 'queue', timestamp: Date.now() });
|
||||
return await handler.execute('create-sessions', payload, context);
|
||||
}),
|
||||
'search-symbols': createJobHandler(async (payload) => {
|
||||
return await handler.execute('search-symbols', payload, {
|
||||
type: 'queue',
|
||||
serviceContainer: container,
|
||||
metadata: { source: 'queue', timestamp: Date.now() }
|
||||
});
|
||||
const context = handler.createExecutionContext('queue', { source: 'queue', timestamp: Date.now() });
|
||||
return await handler.execute('search-symbols', payload, context);
|
||||
}),
|
||||
'spider-symbol-search': createJobHandler(async (payload: SymbolSpiderJob) => {
|
||||
return await handler.execute('spider-symbol-search', payload, {
|
||||
type: 'queue',
|
||||
serviceContainer: container,
|
||||
metadata: { source: 'queue', timestamp: Date.now() }
|
||||
});
|
||||
const context = handler.createExecutionContext('queue', { source: 'queue', timestamp: Date.now() });
|
||||
return await handler.execute('spider-symbol-search', payload, context);
|
||||
}),
|
||||
},
|
||||
|
||||
|
|
@ -134,5 +160,5 @@ export function initializeQMProvider(container: ServiceContainer) {
|
|||
};
|
||||
|
||||
handlerRegistry.registerWithSchedule(qmProviderConfig);
|
||||
handler.logger.debug('QM provider registered successfully with scheduled jobs');
|
||||
}
|
||||
handler.logger.debug('QM provider registered successfully with new DI pattern');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue