handler to auto register and removed service registry, cleaned up queues and cache naming

This commit is contained in:
Boki 2025-06-23 21:23:38 -04:00
parent 0d1be9e3cb
commit 34c6c36695
19 changed files with 474 additions and 198 deletions

View file

@ -159,7 +159,7 @@ export abstract class BaseHandler implements IHandler {
/**
* Create a sub-namespaced cache for specific operations
* Example: handler 'webshare' creates namespace 'webshare:api' -> keys will be 'cache:webshare:api:*'
* Example: handler 'webshare' creates namespace 'webshare:api' -> keys will be 'cache:data-ingestion:webshare:api:*'
*/
protected createNamespacedCache(subNamespace: string) {
return createNamespacedCache(this.cache, `${this.handlerName}:${subNamespace}`);
@ -172,7 +172,8 @@ export abstract class BaseHandler implements IHandler {
if (!this.cache) {
return;
}
return this.cache.set(`cache:${this.handlerName}:${key}`, value, ttl);
// Don't add 'cache:' prefix since the cache already has its own prefix
return this.cache.set(`${this.handlerName}:${key}`, value, ttl);
}
/**
@ -182,7 +183,8 @@ export abstract class BaseHandler implements IHandler {
if (!this.cache) {
return null;
}
return this.cache.get(`cache:${this.handlerName}:${key}`);
// Don't add 'cache:' prefix since the cache already has its own prefix
return this.cache.get(`${this.handlerName}:${key}`);
}
/**
@ -192,7 +194,8 @@ export abstract class BaseHandler implements IHandler {
if (!this.cache) {
return;
}
return this.cache.del(`cache:${this.handlerName}:${key}`);
// Don't add 'cache:' prefix since the cache already has its own prefix
return this.cache.del(`${this.handlerName}:${key}`);
}
/**
@ -294,7 +297,7 @@ export abstract class BaseHandler implements IHandler {
* Register this handler using decorator metadata
* Automatically reads @Handler, @Operation, and @QueueSchedule decorators
*/
register(): void {
register(serviceName?: string): void {
const constructor = this.constructor as any;
const handlerName = constructor.__handlerName || this.handlerName;
const operations = constructor.__operations || [];
@ -333,9 +336,10 @@ export abstract class BaseHandler implements IHandler {
scheduledJobs,
};
handlerRegistry.registerWithSchedule(config);
handlerRegistry.registerWithSchedule(config, serviceName);
this.logger.info('Handler registered using decorator metadata', {
handlerName,
service: serviceName,
operations: operations.map((op: any) => ({ name: op.name, method: op.method })),
scheduledJobs: scheduledJobs.map((job: any) => ({
operation: job.operation,