diff --git a/apps/data-ingestion/src/handlers/qm/actions/session.action.ts b/apps/data-ingestion/src/handlers/qm/actions/session.action.ts index 1ff0278..6237c87 100644 --- a/apps/data-ingestion/src/handlers/qm/actions/session.action.ts +++ b/apps/data-ingestion/src/handlers/qm/actions/session.action.ts @@ -25,7 +25,7 @@ export async function checkSessions(handler: BaseHandler): Promise<{ const neededSessions = SESSION_CONFIG.MAX_SESSIONS - currentCount; for (let i = 0; i < neededSessions; i++) { await handler.scheduleOperation('create-session', { sessionId , sessionType }); - handler.services.logger.log(`Queued job to create session for ${sessionType}`); + handler.logger.info(`Queued job to create session for ${sessionType}`); queuedCount++; } } @@ -50,7 +50,7 @@ export async function createSingleSession( const sessionManager = QMSessionManager.getInstance(); // Get proxy from proxy service - const proxyString = handler.services.proxy.getProxy(); + const proxyString = handler.proxy.getProxy(); // const session = { // proxy: proxyString || 'http://proxy:8080', @@ -60,7 +60,7 @@ export async function createSingleSession( // lastUsed: new Date() // }; - handler.services.logger.info(`Creating session for ${sessionType}`) + handler.logger.info(`Creating session for ${sessionType}`) // Add session to manager // sessionManager.addSession(sessionType, session); diff --git a/libs/core/handlers/src/base/BaseHandler.ts b/libs/core/handlers/src/base/BaseHandler.ts index b2de06c..5338c6f 100644 --- a/libs/core/handlers/src/base/BaseHandler.ts +++ b/libs/core/handlers/src/base/BaseHandler.ts @@ -8,24 +8,34 @@ import type { ExecutionContext, IHandler } from '../types/types'; * Provides common functionality and structure for queue/event operations */ export abstract class BaseHandler implements IHandler { - protected readonly logger; + // Direct service properties - flattened for cleaner access + readonly logger; + readonly cache; + readonly queue; + readonly http; + readonly proxy; + readonly mongodb; + readonly postgres; + readonly questdb; + private handlerName: string; - constructor(readonly services: IServiceContainer, handlerName?: string) { + constructor(services: IServiceContainer, handlerName?: string) { + // Flatten all services onto the handler instance this.logger = getLogger(this.constructor.name); + this.cache = services.cache; + this.queue = services.queue; + this.http = services.http; + this.proxy = services.proxy; + this.mongodb = services.mongodb; + this.postgres = services.postgres; + this.questdb = services.questdb; + // Read handler name from decorator first, then fallback to parameter or class name const constructor = this.constructor as any; this.handlerName = constructor.__handlerName || handlerName || this.constructor.name.toLowerCase(); } - // Convenience getters for common services - protected get mongodb() { return this.services.mongodb; } - protected get postgres() { return this.services.postgres; } - protected get questdb() { return this.services.questdb; } - protected get cache() { return this.services.cache; } - protected get queue() { return this.services.queue; } - protected get http() { return this.services.http; } - /** * Main execution method - automatically routes to decorated methods * Works with queue (events commented for future) @@ -66,7 +76,7 @@ export abstract class BaseHandler implements IHandler { } async scheduleOperation(operation: string, payload: unknown, delay?: number): Promise { - const queue = this.services.queue.getQueue(this.handlerName); + const queue = this.queue.getQueue(this.handlerName); const jobData = { handler: this.handlerName, operation,