fixed cache keys

This commit is contained in:
Boki 2025-06-22 20:34:35 -04:00
parent db3aa9c330
commit 19dfda2392
13 changed files with 286 additions and 221 deletions

View file

@ -1,20 +1,20 @@
import { Queue, type Job } from 'bullmq';
import { getLogger } from '@stock-bot/logger';
import type { DLQConfig, RedisConfig } from './types';
import { getRedisConnection } from './utils';
const logger = getLogger('dlq-handler');
export class DeadLetterQueueHandler {
private dlq: Queue;
private config: Required<DLQConfig>;
private failureCount = new Map<string, number>();
private readonly logger: any;
constructor(
private mainQueue: Queue,
connection: RedisConfig,
config: DLQConfig = {}
config: DLQConfig = {},
logger?: any
) {
this.logger = logger || console;
this.config = {
maxRetries: config.maxRetries ?? 3,
retryDelay: config.retryDelay ?? 60000, // 1 minute
@ -35,7 +35,7 @@ export class DeadLetterQueueHandler {
const currentFailures = (this.failureCount.get(jobKey) || 0) + 1;
this.failureCount.set(jobKey, currentFailures);
logger.warn('Job failed', {
this.logger.warn('Job failed', {
jobId: job.id,
jobName: job.name,
attempt: job.attemptsMade,
@ -80,7 +80,7 @@ export class DeadLetterQueueHandler {
removeOnFail: 50,
});
logger.error('Job moved to DLQ', {
this.logger.error('Job moved to DLQ', {
jobId: job.id,
jobName: job.name,
error: error.message,
@ -89,7 +89,7 @@ export class DeadLetterQueueHandler {
// Check if we need to alert
await this.checkAlertThreshold();
} catch (dlqError) {
logger.error('Failed to move job to DLQ', {
this.logger.error('Failed to move job to DLQ', {
jobId: job.id,
error: dlqError,
});
@ -118,12 +118,12 @@ export class DeadLetterQueueHandler {
await dlqJob.remove();
retriedCount++;
logger.info('Job retried from DLQ', {
this.logger.info('Job retried from DLQ', {
originalJobId: originalJob.id,
jobName: originalJob.name,
});
} catch (error) {
logger.error('Failed to retry DLQ job', {
this.logger.error('Failed to retry DLQ job', {
dlqJobId: dlqJob.id,
error,
});
@ -190,7 +190,7 @@ export class DeadLetterQueueHandler {
}
}
logger.info('DLQ cleanup completed', {
this.logger.info('DLQ cleanup completed', {
removedCount,
cleanupAge: `${this.config.cleanupAge} hours`,
});
@ -205,7 +205,7 @@ export class DeadLetterQueueHandler {
const stats = await this.getStats();
if (stats.total >= this.config.alertThreshold) {
logger.error('DLQ alert threshold exceeded', {
this.logger.error('DLQ alert threshold exceeded', {
threshold: this.config.alertThreshold,
currentCount: stats.total,
byJobName: stats.byJobName,