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

@ -1,6 +1,6 @@
import { createCache, type CacheProvider, type CacheStats } from '@stock-bot/cache';
import type { RedisConfig } from './types';
import { getServiceConfig } from './service-registry';
import { generateCachePrefix } from './service-utils';
/**
* Service-aware cache that uses the service's Redis DB
@ -16,24 +16,18 @@ export class ServiceCache implements CacheProvider {
isGlobalCache: boolean = false,
logger?: any
) {
// Get service configuration
const serviceConfig = getServiceConfig(serviceName);
if (!serviceConfig && !isGlobalCache) {
throw new Error(`Unknown service: ${serviceName}`);
}
// Determine Redis DB and prefix
let db: number;
let prefix: string;
if (isGlobalCache) {
// Global cache uses db:0
db = 0;
// Global cache uses db:1
db = 1;
prefix = 'stock-bot:shared';
} else {
// Service cache uses service's DB
db = serviceConfig!.db;
prefix = serviceConfig!.cachePrefix;
// Service cache also uses db:1 with service-specific prefix
db = 1;
prefix = generateCachePrefix(serviceName);
}
// Create underlying cache with correct DB
@ -148,6 +142,18 @@ export class ServiceCache implements CacheProvider {
return this.cache.set(key, updated, ttl);
}
/**
* Get a value using a raw Redis key (bypassing the keyPrefix)
* Delegates to the underlying cache's getRaw method if available
*/
async getRaw<T = unknown>(key: string): Promise<T | null> {
if (this.cache.getRaw) {
return this.cache.getRaw<T>(key);
}
// Fallback: if underlying cache doesn't support getRaw, return null
return null;
}
/**
* Get the actual Redis key with prefix
*/