reorganized providers to handlers and changed folder structure for maintaiablity

This commit is contained in:
Boki 2025-06-21 09:53:33 -04:00
parent 1bb2380a28
commit 59ab0940ae
11 changed files with 21 additions and 21 deletions

View file

@ -0,0 +1,89 @@
import { getLogger } from '@stock-bot/logger';
import {
createJobHandler,
handlerRegistry,
type HandlerConfigWithSchedule
} from '@stock-bot/queue';
import type { SymbolSpiderJob } from './qm.operations';
const logger = getLogger('qm-provider');
// Initialize and register the QM provider
export function initializeQMProvider() {
logger.debug('Registering QM provider with scheduled jobs...');
const qmProviderConfig: HandlerConfigWithSchedule = {
name: 'qm',
operations: {
'create-sessions': createJobHandler(async () => {
logger.debug('Creating QM sessions...');
const { createSessions } = await import('./qm.operations');
await createSessions();
logger.debug('QM sessions created successfully');
return { success: true, message: 'QM sessions created successfully' };
}),
'search-symbols': createJobHandler(async () => {
logger.info('Starting QM symbol search...');
const { fetchSymbols } = await import('./qm.operations');
const symbols = await fetchSymbols();
if (symbols && symbols.length > 0) {
logger.info('QM symbol search completed successfully', { count: symbols.length });
return {
success: true,
message: 'QM symbol search completed successfully',
count: symbols.length,
symbols: symbols.slice(0, 10), // Return first 10 symbols as sample
};
} else {
logger.warn('QM symbol search returned no results');
return {
success: false,
message: 'No symbols found',
count: 0,
};
}
}),
'spider-symbol-search': createJobHandler(async (payload: SymbolSpiderJob) => {
logger.debug('Processing spider symbol search job', { payload });
const { spiderSymbolSearch } = await import('./qm.operations');
const result = await spiderSymbolSearch(payload);
logger.debug('Spider search job completed', {
success: result.success,
symbolsFound: result.symbolsFound,
});
return result;
}),
},
scheduledJobs: [
{
type: 'session-management',
operation: 'create-sessions',
cronPattern: '0 */15 * * *', // Every 15 minutes
priority: 7,
immediately: true, // Don't run on startup to avoid blocking
description: 'Create and maintain QM sessions',
},
{
type: 'qm-maintnance',
operation: 'spider-symbol-search',
payload: {
prefix: null,
depth: 1,
source: 'qm',
maxDepth: 4
},
cronPattern: '0 0 * * 0', // Every Sunday at midnight
priority: 10,
immediately: true, // Don't run on startup - this is a heavy operation
description: 'Comprehensive symbol search using QM API',
},
],
};
handlerRegistry.registerWithSchedule(qmProviderConfig);
logger.debug('IB provider registered successfully with scheduled jobs');
}