work on new di system
This commit is contained in:
parent
4096e91e67
commit
0c77449584
11 changed files with 161 additions and 39 deletions
|
|
@ -1,16 +1,16 @@
|
|||
import type { IDataIngestionServices } from '@stock-bot/di';
|
||||
import {
|
||||
BaseHandler,
|
||||
Handler,
|
||||
Operation,
|
||||
QueueSchedule,
|
||||
type ExecutionContext
|
||||
type ExecutionContext,
|
||||
type IServiceContainer
|
||||
} from '@stock-bot/handlers';
|
||||
import type { SymbolSpiderJob } from './shared/types';
|
||||
|
||||
@Handler('qm')
|
||||
export class QMHandler extends BaseHandler {
|
||||
constructor(services: IDataIngestionServices) {
|
||||
constructor(services: IServiceContainer) {
|
||||
super(services); // Handler name read from @Handler decorator
|
||||
}
|
||||
|
||||
|
|
@ -21,28 +21,47 @@ export class QMHandler extends BaseHandler {
|
|||
description: 'Create and maintain QM sessions'
|
||||
})
|
||||
async createSessions(input: unknown, context: ExecutionContext): Promise<unknown> {
|
||||
this.logger.info('Creating QM sessions with new DI pattern...');
|
||||
this.logger.info('Creating QM sessions...');
|
||||
|
||||
try {
|
||||
// Check existing sessions in MongoDB
|
||||
const sessionsCollection = this.mongodb.collection('qm_sessions');
|
||||
const existingSessions = await sessionsCollection.find({}).toArray();
|
||||
// Check existing sessions in cache
|
||||
const sessionKey = 'qm:sessions:active';
|
||||
const existingSessions = await this.cache.get(sessionKey) || [];
|
||||
|
||||
this.logger.info('Current QM sessions', {
|
||||
existing: existingSessions.length,
|
||||
action: 'creating_new_sessions'
|
||||
});
|
||||
|
||||
// Cache session stats for monitoring
|
||||
await this.cache.set('qm-sessions-count', existingSessions.length, 3600);
|
||||
await this.cache.set('last-session-check', new Date().toISOString(), 1800);
|
||||
// Create new session
|
||||
const newSession = {
|
||||
id: `qm-session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
||||
createdAt: new Date().toISOString(),
|
||||
status: 'active',
|
||||
provider: 'quotemedia',
|
||||
// Add other session properties as needed
|
||||
};
|
||||
|
||||
// Add to existing sessions
|
||||
const updatedSessions = [...existingSessions, newSession];
|
||||
|
||||
// Store sessions in cache with 24 hour TTL (sessions are temporary)
|
||||
await this.cache.set(sessionKey, updatedSessions, 86400); // 24 hours
|
||||
|
||||
// Store session stats for monitoring
|
||||
await this.cache.set('qm:sessions:count', updatedSessions.length, 3600);
|
||||
await this.cache.set('qm:sessions:last-created', new Date().toISOString(), 1800);
|
||||
|
||||
this.logger.info('QM session created', {
|
||||
sessionId: newSession.id,
|
||||
totalSessions: updatedSessions.length
|
||||
});
|
||||
|
||||
// For now, just return the current state
|
||||
// TODO: Implement actual session creation logic using new DI pattern
|
||||
return {
|
||||
success: true,
|
||||
existingSessions: existingSessions.length,
|
||||
message: 'QM session check completed'
|
||||
sessionId: newSession.id,
|
||||
totalSessions: updatedSessions.length,
|
||||
message: 'QM session created successfully'
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
|
|
@ -90,7 +109,7 @@ export class QMHandler extends BaseHandler {
|
|||
@Operation('spider-symbol-search')
|
||||
@QueueSchedule('0 0 * * 0', {
|
||||
priority: 10,
|
||||
immediately: true,
|
||||
immediately: false,
|
||||
description: 'Comprehensive symbol search using QM API'
|
||||
})
|
||||
async spiderSymbolSearch(payload: SymbolSpiderJob | undefined, context: ExecutionContext): Promise<unknown> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue