work on new di system
This commit is contained in:
parent
4096e91e67
commit
0c77449584
11 changed files with 161 additions and 39 deletions
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
import type { IDataIngestionServices } from '@stock-bot/di';
|
||||
import { createServiceAdapter } from '@stock-bot/di';
|
||||
import { QMHandler } from './qm/qm.handler';
|
||||
import { WebShareHandler } from './webshare/webshare.handler';
|
||||
|
||||
|
|
@ -11,15 +12,18 @@ import { WebShareHandler } from './webshare/webshare.handler';
|
|||
* Initialize and register all handlers
|
||||
*/
|
||||
export function initializeAllHandlers(services: IDataIngestionServices): void {
|
||||
// Create generic service container adapter
|
||||
const serviceContainer = createServiceAdapter(services);
|
||||
|
||||
// QM Handler
|
||||
const qmHandler = new QMHandler(services);
|
||||
const qmHandler = new QMHandler(serviceContainer);
|
||||
qmHandler.register();
|
||||
|
||||
// WebShare Handler
|
||||
const webShareHandler = new WebShareHandler(services);
|
||||
const webShareHandler = new WebShareHandler(serviceContainer);
|
||||
webShareHandler.register();
|
||||
|
||||
// TODO: Add other handlers here as they're converted
|
||||
// const ibHandler = new IBHandler(services);
|
||||
// const ibHandler = new IBHandler(serviceContainer);
|
||||
// ibHandler.register();
|
||||
}
|
||||
|
|
@ -2,17 +2,17 @@
|
|||
* QM Session Operations - Session creation and management
|
||||
*/
|
||||
|
||||
import type { ServiceContainer } from '@stock-bot/di';
|
||||
import { OperationContext } from '@stock-bot/di';
|
||||
import { isShutdownSignalReceived } from '@stock-bot/shutdown';
|
||||
import { getRandomProxy } from '@stock-bot/utils';
|
||||
import type { ServiceContainer } from '@stock-bot/di';
|
||||
|
||||
import { QM_CONFIG, QM_SESSION_IDS, SESSION_CONFIG, getQmHeaders } from '../shared/config';
|
||||
import { QMSessionManager } from '../shared/session-manager';
|
||||
import { QM_SESSION_IDS, QM_CONFIG, SESSION_CONFIG, getQmHeaders } from '../shared/config';
|
||||
import type { QMSession } from '../shared/types';
|
||||
|
||||
export async function createSessions(container: ServiceContainer): Promise<void> {
|
||||
const ctx = new OperationContext('qm-handler', 'create-sessions', container);
|
||||
const ctx = OperationContext.create('qm-handler', 'create-sessions', {container});
|
||||
|
||||
try {
|
||||
ctx.logger.info('Creating QM sessions...');
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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 { updateProxies } from '@stock-bot/utils';
|
||||
|
||||
@Handler('webshare')
|
||||
export class WebShareHandler extends BaseHandler {
|
||||
constructor(services: IDataIngestionServices) {
|
||||
constructor(services: IServiceContainer) {
|
||||
super(services);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ async function initializeServices() {
|
|||
const jobData = {
|
||||
handler: handlerName,
|
||||
operation: scheduledJob.operation,
|
||||
payload: scheduledJob.payload || {},
|
||||
payload: scheduledJob.payload, // Don't default to {} - let it be undefined
|
||||
};
|
||||
|
||||
// Build job options from scheduled job config
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue