work on qm
This commit is contained in:
parent
ca1f658be6
commit
3fb9df425c
5 changed files with 93 additions and 113 deletions
|
|
@ -6,7 +6,6 @@ import {
|
|||
type ExecutionContext,
|
||||
type IServiceContainer
|
||||
} from '@stock-bot/handlers';
|
||||
import type { SymbolSpiderJob } from './shared/types';
|
||||
|
||||
@Handler('qm')
|
||||
export class QMHandler extends BaseHandler {
|
||||
|
|
@ -23,90 +22,90 @@ export class QMHandler extends BaseHandler {
|
|||
async checkSessions(input: unknown, context: ExecutionContext): Promise<unknown> {
|
||||
// Call the session maintenance action
|
||||
const { checkSessions } = await import('./actions/session.action');
|
||||
return await checkSessions(this.services);
|
||||
return await checkSessions(this);
|
||||
}
|
||||
|
||||
@Operation('create-session')
|
||||
async createSession(input: unknown, context: ExecutionContext): Promise<unknown> {
|
||||
// Call the individual session creation action
|
||||
const { createSingleSession } = await import('./actions/session.action');
|
||||
return await createSingleSession(this.services, input);
|
||||
return await createSingleSession(this, input);
|
||||
}
|
||||
|
||||
@Operation('search-symbols')
|
||||
async searchSymbols(_input: unknown, _context: ExecutionContext): Promise<unknown> {
|
||||
this.logger.info('Searching QM symbols with new DI pattern...');
|
||||
try {
|
||||
// Check existing symbols in MongoDB
|
||||
const symbolsCollection = this.mongodb.collection('qm_symbols');
|
||||
const symbols = await symbolsCollection.find({}).limit(100).toArray();
|
||||
// @Operation('search-symbols')
|
||||
// async searchSymbols(_input: unknown, _context: ExecutionContext): Promise<unknown> {
|
||||
// this.logger.info('Searching QM symbols with new DI pattern...');
|
||||
// try {
|
||||
// // Check existing symbols in MongoDB
|
||||
// const symbolsCollection = this.mongodb.collection('qm_symbols');
|
||||
// const symbols = await symbolsCollection.find({}).limit(100).toArray();
|
||||
|
||||
this.logger.info('QM symbol search completed', { count: symbols.length });
|
||||
// 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);
|
||||
// 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',
|
||||
count: symbols.length,
|
||||
symbols: symbols.slice(0, 10), // Return first 10 symbols as sample
|
||||
};
|
||||
} else {
|
||||
// No symbols found - this is expected initially
|
||||
this.logger.info('No QM symbols found in database yet');
|
||||
return {
|
||||
success: true,
|
||||
message: 'No symbols found yet - database is empty',
|
||||
count: 0,
|
||||
};
|
||||
}
|
||||
// return {
|
||||
// success: true,
|
||||
// message: 'QM symbol search completed successfully',
|
||||
// count: symbols.length,
|
||||
// symbols: symbols.slice(0, 10), // Return first 10 symbols as sample
|
||||
// };
|
||||
// } else {
|
||||
// // No symbols found - this is expected initially
|
||||
// this.logger.info('No QM symbols found in database yet');
|
||||
// return {
|
||||
// success: true,
|
||||
// message: 'No symbols found yet - database is empty',
|
||||
// count: 0,
|
||||
// };
|
||||
// }
|
||||
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to search QM symbols', { error });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
// } catch (error) {
|
||||
// this.logger.error('Failed to search QM symbols', { error });
|
||||
// throw error;
|
||||
// }
|
||||
// }
|
||||
|
||||
@Operation('spider-symbol-search')
|
||||
@QueueSchedule('0 0 * * 0', {
|
||||
priority: 10,
|
||||
immediately: false,
|
||||
description: 'Comprehensive symbol search using QM API'
|
||||
})
|
||||
async spiderSymbolSearch(payload: SymbolSpiderJob | undefined, context: ExecutionContext): Promise<unknown> {
|
||||
// Set default payload for scheduled runs
|
||||
const jobPayload: SymbolSpiderJob = payload || {
|
||||
prefix: null,
|
||||
depth: 1,
|
||||
source: 'qm',
|
||||
maxDepth: 4
|
||||
};
|
||||
// @Operation('spider-symbol-search')
|
||||
// @QueueSchedule('0 0 * * 0', {
|
||||
// priority: 10,
|
||||
// immediately: false,
|
||||
// description: 'Comprehensive symbol search using QM API'
|
||||
// })
|
||||
// async spiderSymbolSearch(payload: SymbolSpiderJob | undefined, context: ExecutionContext): Promise<unknown> {
|
||||
// // Set default payload for scheduled runs
|
||||
// const jobPayload: SymbolSpiderJob = payload || {
|
||||
// prefix: null,
|
||||
// depth: 1,
|
||||
// source: 'qm',
|
||||
// maxDepth: 4
|
||||
// };
|
||||
|
||||
this.logger.info('Starting QM spider symbol search', { payload: jobPayload });
|
||||
// this.logger.info('Starting QM spider symbol search', { payload: jobPayload });
|
||||
|
||||
// Store spider job info in cache (temporary data)
|
||||
const spiderJobId = `spider:qm:${Date.now()}:${Math.random().toString(36).substr(2, 9)}`;
|
||||
const spiderResult = {
|
||||
payload: jobPayload,
|
||||
startTime: new Date().toISOString(),
|
||||
status: 'started',
|
||||
jobId: spiderJobId
|
||||
};
|
||||
// // Store spider job info in cache (temporary data)
|
||||
// const spiderJobId = `spider:qm:${Date.now()}:${Math.random().toString(36).substr(2, 9)}`;
|
||||
// const spiderResult = {
|
||||
// payload: jobPayload,
|
||||
// startTime: new Date().toISOString(),
|
||||
// status: 'started',
|
||||
// jobId: spiderJobId
|
||||
// };
|
||||
|
||||
// Store in cache with 1 hour TTL (temporary data)
|
||||
await this.cache.set(spiderJobId, spiderResult, 3600);
|
||||
this.logger.debug('Spider job stored in cache', { spiderJobId, ttl: 3600 });
|
||||
// // Store in cache with 1 hour TTL (temporary data)
|
||||
// await this.cache.set(spiderJobId, spiderResult, 3600);
|
||||
// this.logger.debug('Spider job stored in cache', { spiderJobId, ttl: 3600 });
|
||||
|
||||
// Schedule follow-up processing if needed
|
||||
await this.scheduleOperation('search-symbols', { source: 'spider', spiderJobId }, 5000);
|
||||
// // Schedule follow-up processing if needed
|
||||
// await this.scheduleOperation('search-symbols', { source: 'spider', spiderJobId }, 5000);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'QM spider search initiated',
|
||||
spiderJobId
|
||||
};
|
||||
}
|
||||
// return {
|
||||
// success: true,
|
||||
// message: 'QM spider search initiated',
|
||||
// spiderJobId
|
||||
// };
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue