refactored handler
This commit is contained in:
parent
62a2f15dab
commit
8b17f98845
2 changed files with 24 additions and 14 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<void> {
|
||||
const queue = this.services.queue.getQueue(this.handlerName);
|
||||
const queue = this.queue.getQueue(this.handlerName);
|
||||
const jobData = {
|
||||
handler: this.handlerName,
|
||||
operation,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue