lint issues
This commit is contained in:
parent
19dfda2392
commit
190b725149
7 changed files with 71 additions and 28 deletions
|
|
@ -105,7 +105,7 @@ export function createServiceContainer(rawConfig: unknown): AwilixContainer<Serv
|
|||
});
|
||||
|
||||
// Register configuration values
|
||||
const registrations: any = {
|
||||
const registrations: Record<string, unknown> = {
|
||||
// Configuration
|
||||
config: asValue(config),
|
||||
redisConfig: asValue(config.redis),
|
||||
|
|
@ -177,7 +177,7 @@ export function createServiceContainer(rawConfig: unknown): AwilixContainer<Serv
|
|||
// Conditionally register QuestDB client
|
||||
if (config.questdb?.enabled !== false) {
|
||||
registrations.questdbClient = asFunction(({ questdbConfig, logger }) => {
|
||||
console.log('Creating QuestDB client with config:', questdbConfig);
|
||||
logger.debug('Creating QuestDB client with config:', questdbConfig);
|
||||
return new QuestDBClient(
|
||||
{
|
||||
host: questdbConfig.host,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,14 +51,12 @@ describe('QueueManager', () => {
|
|||
describe('Basic Operations', () => {
|
||||
test('should initialize queue manager', async () => {
|
||||
queueManager = new QueueManager({
|
||||
queueName: 'test-queue',
|
||||
redis: redisConfig,
|
||||
workers: 1,
|
||||
concurrency: 5,
|
||||
});
|
||||
|
||||
await queueManager.initialize();
|
||||
expect(queueManager.queueName).toBe('test-queue');
|
||||
// No need to initialize anymore - constructor handles everything
|
||||
// QueueManager now manages multiple queues, not just one
|
||||
expect(queueManager).toBeDefined();
|
||||
});
|
||||
|
||||
test('should add and process a job', async () => {
|
||||
|
|
@ -73,15 +71,17 @@ describe('QueueManager', () => {
|
|||
});
|
||||
|
||||
queueManager = new QueueManager({
|
||||
queueName: 'test-queue',
|
||||
redis: redisConfig,
|
||||
});
|
||||
|
||||
// No need to initialize anymore - constructor handles everything
|
||||
// Get or create a queue
|
||||
const queue = queueManager.getQueue('test-queue', {
|
||||
workers: 1,
|
||||
});
|
||||
|
||||
await queueManager.initialize();
|
||||
|
||||
// Add job
|
||||
const job = await queueManager.add('test-job', {
|
||||
const job = await queue.add('test-job', {
|
||||
handler: 'test-handler',
|
||||
operation: 'test-operation',
|
||||
payload: { message: 'Hello, Queue!' },
|
||||
|
|
@ -102,7 +102,7 @@ describe('QueueManager', () => {
|
|||
workers: 1,
|
||||
});
|
||||
|
||||
await queueManager.initialize();
|
||||
// No need to initialize anymore - constructor handles everything
|
||||
|
||||
const job = await queueManager.add('test-job', {
|
||||
handler: 'non-existent',
|
||||
|
|
@ -134,7 +134,7 @@ describe('QueueManager', () => {
|
|||
concurrency: 5,
|
||||
});
|
||||
|
||||
await queueManager.initialize();
|
||||
// No need to initialize anymore - constructor handles everything
|
||||
|
||||
const jobs = await queueManager.addBulk([
|
||||
{
|
||||
|
|
@ -166,7 +166,7 @@ describe('QueueManager', () => {
|
|||
workers: 0, // No workers, jobs will stay in waiting
|
||||
});
|
||||
|
||||
await queueManager.initialize();
|
||||
// No need to initialize anymore - constructor handles everything
|
||||
|
||||
// Add some jobs
|
||||
await queueManager.add('job1', {
|
||||
|
|
@ -205,7 +205,7 @@ describe('QueueManager', () => {
|
|||
workers: 1,
|
||||
});
|
||||
|
||||
await queueManager.initialize();
|
||||
// No need to initialize anymore - constructor handles everything
|
||||
|
||||
// Pause queue
|
||||
await queueManager.pause();
|
||||
|
|
@ -260,7 +260,7 @@ describe('QueueManager', () => {
|
|||
enableScheduledJobs: true,
|
||||
});
|
||||
|
||||
await queueManager.initialize();
|
||||
// No need to initialize anymore - constructor handles everything
|
||||
|
||||
// Wait for scheduled job to execute
|
||||
await new Promise(resolve => setTimeout(resolve, 2500));
|
||||
|
|
@ -296,7 +296,7 @@ describe('QueueManager', () => {
|
|||
},
|
||||
});
|
||||
|
||||
await queueManager.initialize();
|
||||
// No need to initialize anymore - constructor handles everything
|
||||
|
||||
const job = await queueManager.add('retry-job', {
|
||||
handler: 'retry-handler',
|
||||
|
|
@ -341,7 +341,7 @@ describe('QueueManager', () => {
|
|||
workers: 2,
|
||||
});
|
||||
|
||||
await queueManager.initialize();
|
||||
// No need to initialize anymore - constructor handles everything
|
||||
|
||||
// Add jobs for different handlers
|
||||
await queueManager.addBulk([
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue