fix(core): own cache transports and accept cleanup reviews
This commit is contained in:
parent
bd9332b2f6
commit
b4ac6460ef
24 changed files with 504 additions and 97 deletions
|
|
@ -23,6 +23,7 @@ export interface ServiceDefinitions {
|
|||
// Core services
|
||||
cache: CacheProvider | null;
|
||||
globalCache: CacheProvider | null;
|
||||
proxyCache: CacheProvider | null;
|
||||
proxyManager: ProxyManager | null;
|
||||
browser: Browser | null;
|
||||
queueManager: QueueManager | null;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@ export function registerCacheServices(
|
|||
config: AppConfig
|
||||
): void {
|
||||
if (config.redis?.enabled) {
|
||||
if (config.redis.keyPrefix !== undefined) {
|
||||
container
|
||||
.resolve('logger')
|
||||
.warn(
|
||||
'Redis keyPrefix is deprecated at the DI boundary; service/global/proxy namespaces remain fixed'
|
||||
);
|
||||
}
|
||||
container.register({
|
||||
cache: asFunction(({ logger }) => {
|
||||
const { createServiceCache } = require('@stock-bot/queue');
|
||||
|
|
@ -21,11 +28,15 @@ export function registerCacheServices(
|
|||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
username: config.redis.username,
|
||||
maxRetriesPerRequest: config.redis.maxRetries,
|
||||
retryDelay: config.redis.retryDelay,
|
||||
db: config.redis.db, // This will be overridden by ServiceCache
|
||||
},
|
||||
{ logger }
|
||||
{ logger, shared: false, ttl: config.redis.ttl }
|
||||
);
|
||||
}).singleton(),
|
||||
})
|
||||
.singleton()
|
||||
.disposer(cache => cache.disconnect()),
|
||||
|
||||
// Also provide global cache for shared data
|
||||
globalCache: asFunction(({ logger }) => {
|
||||
|
|
@ -39,10 +50,14 @@ export function registerCacheServices(
|
|||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
username: config.redis.username,
|
||||
maxRetriesPerRequest: config.redis.maxRetries,
|
||||
retryDelay: config.redis.retryDelay,
|
||||
},
|
||||
{ global: true, logger }
|
||||
{ global: true, logger, shared: false, ttl: config.redis.ttl }
|
||||
);
|
||||
}).singleton(),
|
||||
})
|
||||
.singleton()
|
||||
.disposer(cache => cache.disconnect()),
|
||||
});
|
||||
} else {
|
||||
container.register({
|
||||
|
|
|
|||
|
|
@ -76,6 +76,16 @@ export function registerDatabaseServices(
|
|||
if (config.questdb?.enabled) {
|
||||
container.register({
|
||||
questdbClient: asFunction(({ logger }) => {
|
||||
// Compatibility fields never configured the writer. Warn on requested tuning,
|
||||
// rather than pretending bytes map to its explicit per-operation row batching.
|
||||
if (
|
||||
defined(config.questdb).bufferSize !== 65536 ||
|
||||
defined(config.questdb).flushInterval !== 1000
|
||||
) {
|
||||
logger.warn(
|
||||
'QuestDB bufferSize/flushInterval are deprecated and have no effect; configure explicit writer batch options instead'
|
||||
);
|
||||
}
|
||||
return new QuestDBClient(
|
||||
{
|
||||
host: defined(config.questdb).host,
|
||||
|
|
|
|||
|
|
@ -30,31 +30,35 @@ export function registerApplicationServices(
|
|||
// Proxy Manager
|
||||
if (config.proxy && config.redis?.enabled) {
|
||||
container.register({
|
||||
proxyManager: asFunction(({ logger }) => {
|
||||
proxyCache: asFunction(({ logger }) => {
|
||||
// Create a separate cache instance for proxy with global prefix
|
||||
const { createCache } = require('@stock-bot/cache');
|
||||
const proxyCache = createCache({
|
||||
return createCache({
|
||||
redisConfig: {
|
||||
host: config.redis.host,
|
||||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
username: config.redis.username,
|
||||
maxRetriesPerRequest: config.redis.maxRetries,
|
||||
retryDelay: config.redis.retryDelay,
|
||||
db: 1, // Use cache DB (usually DB 1)
|
||||
},
|
||||
shared: false,
|
||||
keyPrefix: 'cache:proxy:',
|
||||
ttl: 86400, // 24 hours default
|
||||
enableMetrics: true,
|
||||
logger,
|
||||
});
|
||||
|
||||
const proxyManager = new ProxyManager(proxyCache, config.proxy, logger);
|
||||
|
||||
// Note: Initialization will be handled by the lifecycle manager
|
||||
return proxyManager;
|
||||
}).singleton(),
|
||||
})
|
||||
.singleton()
|
||||
.disposer(cache => cache.disconnect?.()),
|
||||
proxyManager: asFunction(
|
||||
({ logger, proxyCache }) => new ProxyManager(defined(proxyCache), config.proxy, logger)
|
||||
).singleton(),
|
||||
});
|
||||
} else {
|
||||
container.register({
|
||||
proxyCache: asValue(null),
|
||||
proxyManager: asValue(null),
|
||||
});
|
||||
}
|
||||
|
|
@ -72,6 +76,8 @@ export function registerApplicationServices(
|
|||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
username: config.redis.username,
|
||||
maxRetriesPerRequest: config.redis.maxRetries,
|
||||
retryDelay: config.redis.retryDelay,
|
||||
db: config.redis.db,
|
||||
},
|
||||
defaultQueueOptions: {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ export class ServiceLifecycleManager {
|
|||
private readonly logger = getLogger('service-lifecycle');
|
||||
private readonly services = [
|
||||
{ name: 'cache', key: 'cache' as const },
|
||||
{ name: 'globalCache', key: 'globalCache' as const },
|
||||
{ name: 'proxyCache', key: 'proxyCache' as const },
|
||||
{ name: 'mongoClient', key: 'mongoClient' as const },
|
||||
{ name: 'postgresClient', key: 'postgresClient' as const },
|
||||
{ name: 'questdbClient', key: 'questdbClient' as const },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue