commit 2 refactor
This commit is contained in:
parent
588f666943
commit
32e43c9243
310 changed files with 33318 additions and 31189 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import { Queue as BullQueue, type Job } from 'bullmq';
|
||||
import Redis from 'ioredis';
|
||||
import type { CacheProvider } from '@stock-bot/cache';
|
||||
import { createCache } from '@stock-bot/cache';
|
||||
import type { HandlerRegistry } from '@stock-bot/handler-registry';
|
||||
import { defined } from '@stock-bot/invariants';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import type { LoggerLike as Logger } from '@stock-bot/logger';
|
||||
import Redis from 'ioredis';
|
||||
import { Queue, type QueueWorkerConfig } from './queue';
|
||||
import { QueueRateLimiter } from './rate-limiter';
|
||||
import { getFullQueueName, parseQueueName } from './service-utils';
|
||||
|
|
@ -58,7 +59,7 @@ export class QueueManager {
|
|||
this.handlerRegistry = handlerRegistry;
|
||||
this.logger = logger || getLogger('QueueManager');
|
||||
this.redisConnection = getRedisConnection(config.redis);
|
||||
|
||||
|
||||
// Create ioredis connection for rate limiter
|
||||
this.ioredisConnection = new Redis({
|
||||
host: config.redis.host,
|
||||
|
|
@ -311,8 +312,8 @@ export class QueueManager {
|
|||
}
|
||||
this.rateLimiter = new QueueRateLimiter(this.ioredisConnection, this.logger);
|
||||
}
|
||||
await Promise.all(rules.map(rule => this.rateLimiter!.addRule(rule)));
|
||||
|
||||
await Promise.all(rules.map(rule => defined(this.rateLimiter).addRule(rule)));
|
||||
|
||||
this.logger.info('Added rate limit rules to QueueManager', {
|
||||
ruleCount: rules.length,
|
||||
rules,
|
||||
|
|
@ -339,10 +340,10 @@ export class QueueManager {
|
|||
// Support both 2-parameter and 3-parameter calls
|
||||
let handler: string;
|
||||
let operation: string | undefined;
|
||||
|
||||
|
||||
if (operationIfThreeParams !== undefined) {
|
||||
// 3-parameter call: checkRateLimit(queueName, handler, operation)
|
||||
handler = operationOrHandler!;
|
||||
handler = defined(operationOrHandler);
|
||||
operation = operationIfThreeParams;
|
||||
} else {
|
||||
// 2-parameter call: checkRateLimit(handler, operation)
|
||||
|
|
@ -375,7 +376,7 @@ export class QueueManager {
|
|||
const status = await this.rateLimiter.getStatus(handler, operation);
|
||||
return {
|
||||
queueName,
|
||||
...status
|
||||
...status,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -478,8 +479,8 @@ export class QueueManager {
|
|||
try {
|
||||
// Add timeout to queue.close() to prevent hanging
|
||||
const closePromise = queue.close();
|
||||
const timeoutPromise = new Promise<never>((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Queue close timeout')), 5000) // 5 second timeout per queue
|
||||
const timeoutPromise = new Promise<never>(
|
||||
(_, reject) => setTimeout(() => reject(new Error('Queue close timeout')), 5000) // 5 second timeout per queue
|
||||
);
|
||||
|
||||
await Promise.race([closePromise, timeoutPromise]);
|
||||
|
|
@ -501,7 +502,7 @@ export class QueueManager {
|
|||
});
|
||||
|
||||
await Promise.all(cacheShutdownPromises);
|
||||
|
||||
|
||||
// Close ioredis connection
|
||||
if (this.ioredisConnection) {
|
||||
try {
|
||||
|
|
@ -699,7 +700,7 @@ export class QueueManager {
|
|||
});
|
||||
this.producerQueues.set(queueName, queue);
|
||||
}
|
||||
return this.producerQueues.get(queueName)!;
|
||||
return defined(this.producerQueues.get(queueName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -724,7 +725,7 @@ export class QueueManager {
|
|||
service: ownerService,
|
||||
handler: handlerName,
|
||||
db: 0, // All queues in DB 0
|
||||
operations: metadata.operations.map((op: any) => op.name),
|
||||
operations: metadata.operations.map(op => op.name),
|
||||
});
|
||||
|
||||
this.logger.trace('Discovered queue route', {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue