lint issues
This commit is contained in:
parent
19dfda2392
commit
190b725149
7 changed files with 71 additions and 28 deletions
|
|
@ -49,7 +49,7 @@ export async function processItems<T>(
|
|||
|
||||
return { ...result, duration };
|
||||
} catch (error) {
|
||||
logger.error('Batch processing failed', error);
|
||||
logger.error('Batch processing failed', { error });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,25 @@ import { Queue, type Job } from 'bullmq';
|
|||
import type { DLQConfig, RedisConfig } from './types';
|
||||
import { getRedisConnection } from './utils';
|
||||
|
||||
// Logger interface for type safety
|
||||
interface Logger {
|
||||
info(message: string, meta?: Record<string, unknown>): void;
|
||||
error(message: string, meta?: Record<string, unknown>): void;
|
||||
warn(message: string, meta?: Record<string, unknown>): void;
|
||||
debug(message: string, meta?: Record<string, unknown>): void;
|
||||
}
|
||||
|
||||
export class DeadLetterQueueHandler {
|
||||
private dlq: Queue;
|
||||
private config: Required<DLQConfig>;
|
||||
private failureCount = new Map<string, number>();
|
||||
private readonly logger: any;
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(
|
||||
private mainQueue: Queue,
|
||||
connection: RedisConfig,
|
||||
config: DLQConfig = {},
|
||||
logger?: any
|
||||
logger?: Logger
|
||||
) {
|
||||
this.logger = logger || console;
|
||||
this.config = {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,16 @@ import type {
|
|||
} from './types';
|
||||
import { getRedisConnection } from './utils';
|
||||
|
||||
// Logger interface for type safety
|
||||
interface Logger {
|
||||
info(message: string, meta?: Record<string, unknown>): void;
|
||||
error(message: string, meta?: Record<string, unknown>): void;
|
||||
warn(message: string, meta?: Record<string, unknown>): void;
|
||||
debug(message: string, meta?: Record<string, unknown>): void;
|
||||
trace(message: string, meta?: Record<string, unknown>): void;
|
||||
child?(name: string, context?: Record<string, unknown>): Logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* QueueManager provides unified queue and cache management
|
||||
* Main entry point for all queue operations with getQueue() method
|
||||
|
|
@ -24,9 +34,9 @@ export class QueueManager {
|
|||
private isShuttingDown = false;
|
||||
private shutdownPromise: Promise<void> | null = null;
|
||||
private config: QueueManagerConfig;
|
||||
private readonly logger: any;
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(config: QueueManagerConfig, logger?: any) {
|
||||
constructor(config: QueueManagerConfig, logger?: Logger) {
|
||||
this.config = config;
|
||||
this.logger = logger || console;
|
||||
this.redisConnection = getRedisConnection(config.redis);
|
||||
|
|
@ -52,6 +62,8 @@ export class QueueManager {
|
|||
* @throws Error if not initialized - use initialize() first
|
||||
*/
|
||||
static getInstance(): QueueManager {
|
||||
// Deprecated warning - using console since we don't have a logger instance
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
'QueueManager.getInstance() is deprecated. Please use dependency injection instead.'
|
||||
);
|
||||
|
|
@ -67,10 +79,13 @@ export class QueueManager {
|
|||
* Must be called before getInstance()
|
||||
*/
|
||||
static initialize(config: QueueManagerConfig): QueueManager {
|
||||
// Deprecated warning - using console since we don't have a logger instance
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
'QueueManager.initialize() is deprecated. Please use dependency injection instead.'
|
||||
);
|
||||
if (QueueManager.instance) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('QueueManager already initialized, returning existing instance');
|
||||
return QueueManager.instance;
|
||||
}
|
||||
|
|
@ -84,6 +99,8 @@ export class QueueManager {
|
|||
* Convenience method that combines initialize and getInstance
|
||||
*/
|
||||
static getOrInitialize(config?: QueueManagerConfig): QueueManager {
|
||||
// Deprecated warning - using console since we don't have a logger instance
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
'QueueManager.getOrInitialize() is deprecated. Please use dependency injection instead.'
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,16 @@ import { handlerRegistry } from '@stock-bot/types';
|
|||
import type { JobData, JobOptions, QueueStats, RedisConfig } from './types';
|
||||
import { getRedisConnection } from './utils';
|
||||
|
||||
// Logger interface for type safety
|
||||
interface Logger {
|
||||
info(message: string, meta?: Record<string, unknown>): void;
|
||||
error(message: string, meta?: Record<string, unknown>): void;
|
||||
warn(message: string, meta?: Record<string, unknown>): void;
|
||||
debug(message: string, meta?: Record<string, unknown>): void;
|
||||
trace(message: string, meta?: Record<string, unknown>): void;
|
||||
child?(name: string, context?: Record<string, unknown>): Logger;
|
||||
}
|
||||
|
||||
export interface QueueWorkerConfig {
|
||||
workers?: number;
|
||||
concurrency?: number;
|
||||
|
|
@ -19,14 +29,14 @@ export class Queue {
|
|||
private queueEvents?: QueueEvents;
|
||||
private queueName: string;
|
||||
private redisConfig: RedisConfig;
|
||||
private readonly logger: any;
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(
|
||||
queueName: string,
|
||||
redisConfig: RedisConfig,
|
||||
defaultJobOptions: JobOptions = {},
|
||||
config: QueueWorkerConfig = {},
|
||||
logger?: any
|
||||
logger?: Logger
|
||||
) {
|
||||
this.queueName = queueName;
|
||||
this.redisConfig = redisConfig;
|
||||
|
|
@ -246,7 +256,7 @@ export class Queue {
|
|||
* Create a child logger with additional context
|
||||
* Useful for batch processing and other queue operations
|
||||
*/
|
||||
createChildLogger(name: string, context?: any) {
|
||||
createChildLogger(name: string, context?: Record<string, unknown>) {
|
||||
if (this.logger && typeof this.logger.child === 'function') {
|
||||
return this.logger.child(name, context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,14 @@
|
|||
import { RateLimiterRedis, RateLimiterRes } from 'rate-limiter-flexible';
|
||||
import type { RateLimitConfig as BaseRateLimitConfig, RateLimitRule } from './types';
|
||||
|
||||
// Logger interface for type safety
|
||||
interface Logger {
|
||||
info(message: string, meta?: Record<string, unknown>): void;
|
||||
error(message: string, meta?: Record<string, unknown>): void;
|
||||
warn(message: string, meta?: Record<string, unknown>): void;
|
||||
debug(message: string, meta?: Record<string, unknown>): void;
|
||||
}
|
||||
|
||||
// Extend the base config to add rate-limiter specific fields
|
||||
export interface RateLimitConfig extends BaseRateLimitConfig {
|
||||
keyPrefix?: string;
|
||||
|
|
@ -9,11 +17,11 @@ export interface RateLimitConfig extends BaseRateLimitConfig {
|
|||
export class QueueRateLimiter {
|
||||
private limiters = new Map<string, RateLimiterRedis>();
|
||||
private rules: RateLimitRule[] = [];
|
||||
private readonly logger: any;
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(
|
||||
private redisClient: ReturnType<typeof import('./utils').getRedisConnection>,
|
||||
logger?: any
|
||||
logger?: Logger
|
||||
) {
|
||||
this.logger = logger || console;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue