fixed up qm and added types to BaseHandler for typesafety
This commit is contained in:
parent
87b1cad4f5
commit
2e86598262
20 changed files with 164 additions and 109 deletions
|
|
@ -40,41 +40,41 @@ export interface JobScheduleOptions {
|
|||
* Abstract base class for all handlers with improved DI
|
||||
* Provides common functionality and structure for queue/event operations
|
||||
*/
|
||||
export abstract class BaseHandler implements IHandler {
|
||||
export abstract class BaseHandler<TServices extends ServiceTypes = ServiceTypes> implements IHandler {
|
||||
// Direct service properties - flattened for cleaner access with proper types
|
||||
readonly logger: ServiceTypes['logger'];
|
||||
readonly cache: ServiceTypes['cache'];
|
||||
readonly globalCache: ServiceTypes['globalCache'];
|
||||
readonly queueManager: ServiceTypes['queueManager'];
|
||||
readonly queue: ServiceTypes['queue']; // Specific queue for this handler
|
||||
readonly proxy: ServiceTypes['proxy'];
|
||||
readonly browser: ServiceTypes['browser'];
|
||||
readonly mongodb: ServiceTypes['mongodb'];
|
||||
readonly postgres: ServiceTypes['postgres'];
|
||||
readonly questdb: ServiceTypes['questdb'];
|
||||
readonly logger: TServices['logger'];
|
||||
readonly cache: TServices['cache'];
|
||||
readonly globalCache: TServices['globalCache'];
|
||||
readonly queueManager: TServices['queueManager'];
|
||||
readonly queue!: TServices['queue']; // Specific queue for this handler - initialized if queueManager exists
|
||||
readonly proxy: TServices['proxy'];
|
||||
readonly browser: TServices['browser'];
|
||||
readonly mongodb: TServices['mongodb'];
|
||||
readonly postgres: TServices['postgres'];
|
||||
readonly questdb: TServices['questdb'];
|
||||
|
||||
private handlerName: string;
|
||||
|
||||
constructor(services: IServiceContainer, handlerName?: string) {
|
||||
constructor(services: TServices, handlerName?: string) {
|
||||
// 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();
|
||||
|
||||
// Flatten all services onto the handler instance
|
||||
this.logger = getLogger(this.constructor.name);
|
||||
this.cache = services.cache;
|
||||
this.globalCache = services.globalCache;
|
||||
this.queueManager = services.queueManager;
|
||||
this.proxy = services.proxy;
|
||||
this.browser = services.browser;
|
||||
this.mongodb = services.mongodb;
|
||||
this.postgres = services.postgres;
|
||||
this.questdb = services.questdb;
|
||||
this.logger = getLogger(this.constructor.name) as TServices['logger'];
|
||||
this.cache = services.cache as TServices['cache'];
|
||||
this.globalCache = services.globalCache as TServices['globalCache'];
|
||||
this.queueManager = services.queueManager as TServices['queueManager'];
|
||||
this.proxy = services.proxy as TServices['proxy'];
|
||||
this.browser = services.browser as TServices['browser'];
|
||||
this.mongodb = services.mongodb as TServices['mongodb'];
|
||||
this.postgres = services.postgres as TServices['postgres'];
|
||||
this.questdb = services.questdb as TServices['questdb'];
|
||||
|
||||
// Get the specific queue for this handler
|
||||
if (this.queueManager) {
|
||||
this.queue = this.queueManager.getQueue(this.handlerName);
|
||||
this.queue = this.queueManager.getQueue(this.handlerName) as TServices['queue'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue