This commit is contained in:
Boki 2025-06-21 23:13:07 -04:00
parent 0c77449584
commit ca1f658be6
9 changed files with 170 additions and 766 deletions

View file

@ -14,60 +14,23 @@ export class QMHandler extends BaseHandler {
super(services); // Handler name read from @Handler decorator
}
@Operation('create-sessions')
@Operation('check-sessions')
@QueueSchedule('0 */15 * * *', {
priority: 7,
immediately: true,
description: 'Create and maintain QM sessions'
description: 'Check and maintain QM sessions'
})
async createSessions(input: unknown, context: ExecutionContext): Promise<unknown> {
this.logger.info('Creating QM sessions...');
try {
// 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'
});
// 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
});
return {
success: true,
sessionId: newSession.id,
totalSessions: updatedSessions.length,
message: 'QM session created successfully'
};
} catch (error) {
this.logger.error('Failed to create QM sessions', { error });
throw error;
}
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);
}
@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);
}
@Operation('search-symbols')