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
|
// Register configuration values
|
||||||
const registrations: any = {
|
const registrations: Record<string, unknown> = {
|
||||||
// Configuration
|
// Configuration
|
||||||
config: asValue(config),
|
config: asValue(config),
|
||||||
redisConfig: asValue(config.redis),
|
redisConfig: asValue(config.redis),
|
||||||
|
|
@ -177,7 +177,7 @@ export function createServiceContainer(rawConfig: unknown): AwilixContainer<Serv
|
||||||
// Conditionally register QuestDB client
|
// Conditionally register QuestDB client
|
||||||
if (config.questdb?.enabled !== false) {
|
if (config.questdb?.enabled !== false) {
|
||||||
registrations.questdbClient = asFunction(({ questdbConfig, logger }) => {
|
registrations.questdbClient = asFunction(({ questdbConfig, logger }) => {
|
||||||
console.log('Creating QuestDB client with config:', questdbConfig);
|
logger.debug('Creating QuestDB client with config:', questdbConfig);
|
||||||
return new QuestDBClient(
|
return new QuestDBClient(
|
||||||
{
|
{
|
||||||
host: questdbConfig.host,
|
host: questdbConfig.host,
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ export async function processItems<T>(
|
||||||
|
|
||||||
return { ...result, duration };
|
return { ...result, duration };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Batch processing failed', error);
|
logger.error('Batch processing failed', { error });
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,25 @@ import { Queue, type Job } from 'bullmq';
|
||||||
import type { DLQConfig, RedisConfig } from './types';
|
import type { DLQConfig, RedisConfig } from './types';
|
||||||
import { getRedisConnection } from './utils';
|
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 {
|
export class DeadLetterQueueHandler {
|
||||||
private dlq: Queue;
|
private dlq: Queue;
|
||||||
private config: Required<DLQConfig>;
|
private config: Required<DLQConfig>;
|
||||||
private failureCount = new Map<string, number>();
|
private failureCount = new Map<string, number>();
|
||||||
private readonly logger: any;
|
private readonly logger: Logger;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private mainQueue: Queue,
|
private mainQueue: Queue,
|
||||||
connection: RedisConfig,
|
connection: RedisConfig,
|
||||||
config: DLQConfig = {},
|
config: DLQConfig = {},
|
||||||
logger?: any
|
logger?: Logger
|
||||||
) {
|
) {
|
||||||
this.logger = logger || console;
|
this.logger = logger || console;
|
||||||
this.config = {
|
this.config = {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,16 @@ import type {
|
||||||
} from './types';
|
} from './types';
|
||||||
import { getRedisConnection } from './utils';
|
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
|
* QueueManager provides unified queue and cache management
|
||||||
* Main entry point for all queue operations with getQueue() method
|
* Main entry point for all queue operations with getQueue() method
|
||||||
|
|
@ -24,9 +34,9 @@ export class QueueManager {
|
||||||
private isShuttingDown = false;
|
private isShuttingDown = false;
|
||||||
private shutdownPromise: Promise<void> | null = null;
|
private shutdownPromise: Promise<void> | null = null;
|
||||||
private config: QueueManagerConfig;
|
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.config = config;
|
||||||
this.logger = logger || console;
|
this.logger = logger || console;
|
||||||
this.redisConnection = getRedisConnection(config.redis);
|
this.redisConnection = getRedisConnection(config.redis);
|
||||||
|
|
@ -52,6 +62,8 @@ export class QueueManager {
|
||||||
* @throws Error if not initialized - use initialize() first
|
* @throws Error if not initialized - use initialize() first
|
||||||
*/
|
*/
|
||||||
static getInstance(): QueueManager {
|
static getInstance(): QueueManager {
|
||||||
|
// Deprecated warning - using console since we don't have a logger instance
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
console.warn(
|
console.warn(
|
||||||
'QueueManager.getInstance() is deprecated. Please use dependency injection instead.'
|
'QueueManager.getInstance() is deprecated. Please use dependency injection instead.'
|
||||||
);
|
);
|
||||||
|
|
@ -67,10 +79,13 @@ export class QueueManager {
|
||||||
* Must be called before getInstance()
|
* Must be called before getInstance()
|
||||||
*/
|
*/
|
||||||
static initialize(config: QueueManagerConfig): QueueManager {
|
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(
|
console.warn(
|
||||||
'QueueManager.initialize() is deprecated. Please use dependency injection instead.'
|
'QueueManager.initialize() is deprecated. Please use dependency injection instead.'
|
||||||
);
|
);
|
||||||
if (QueueManager.instance) {
|
if (QueueManager.instance) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
console.warn('QueueManager already initialized, returning existing instance');
|
console.warn('QueueManager already initialized, returning existing instance');
|
||||||
return QueueManager.instance;
|
return QueueManager.instance;
|
||||||
}
|
}
|
||||||
|
|
@ -84,6 +99,8 @@ export class QueueManager {
|
||||||
* Convenience method that combines initialize and getInstance
|
* Convenience method that combines initialize and getInstance
|
||||||
*/
|
*/
|
||||||
static getOrInitialize(config?: QueueManagerConfig): QueueManager {
|
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(
|
console.warn(
|
||||||
'QueueManager.getOrInitialize() is deprecated. Please use dependency injection instead.'
|
'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 type { JobData, JobOptions, QueueStats, RedisConfig } from './types';
|
||||||
import { getRedisConnection } from './utils';
|
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 {
|
export interface QueueWorkerConfig {
|
||||||
workers?: number;
|
workers?: number;
|
||||||
concurrency?: number;
|
concurrency?: number;
|
||||||
|
|
@ -19,14 +29,14 @@ export class Queue {
|
||||||
private queueEvents?: QueueEvents;
|
private queueEvents?: QueueEvents;
|
||||||
private queueName: string;
|
private queueName: string;
|
||||||
private redisConfig: RedisConfig;
|
private redisConfig: RedisConfig;
|
||||||
private readonly logger: any;
|
private readonly logger: Logger;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
queueName: string,
|
queueName: string,
|
||||||
redisConfig: RedisConfig,
|
redisConfig: RedisConfig,
|
||||||
defaultJobOptions: JobOptions = {},
|
defaultJobOptions: JobOptions = {},
|
||||||
config: QueueWorkerConfig = {},
|
config: QueueWorkerConfig = {},
|
||||||
logger?: any
|
logger?: Logger
|
||||||
) {
|
) {
|
||||||
this.queueName = queueName;
|
this.queueName = queueName;
|
||||||
this.redisConfig = redisConfig;
|
this.redisConfig = redisConfig;
|
||||||
|
|
@ -246,7 +256,7 @@ export class Queue {
|
||||||
* Create a child logger with additional context
|
* Create a child logger with additional context
|
||||||
* Useful for batch processing and other queue operations
|
* 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') {
|
if (this.logger && typeof this.logger.child === 'function') {
|
||||||
return this.logger.child(name, context);
|
return this.logger.child(name, context);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
import { RateLimiterRedis, RateLimiterRes } from 'rate-limiter-flexible';
|
import { RateLimiterRedis, RateLimiterRes } from 'rate-limiter-flexible';
|
||||||
import type { RateLimitConfig as BaseRateLimitConfig, RateLimitRule } from './types';
|
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
|
// Extend the base config to add rate-limiter specific fields
|
||||||
export interface RateLimitConfig extends BaseRateLimitConfig {
|
export interface RateLimitConfig extends BaseRateLimitConfig {
|
||||||
keyPrefix?: string;
|
keyPrefix?: string;
|
||||||
|
|
@ -9,11 +17,11 @@ export interface RateLimitConfig extends BaseRateLimitConfig {
|
||||||
export class QueueRateLimiter {
|
export class QueueRateLimiter {
|
||||||
private limiters = new Map<string, RateLimiterRedis>();
|
private limiters = new Map<string, RateLimiterRedis>();
|
||||||
private rules: RateLimitRule[] = [];
|
private rules: RateLimitRule[] = [];
|
||||||
private readonly logger: any;
|
private readonly logger: Logger;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private redisClient: ReturnType<typeof import('./utils').getRedisConnection>,
|
private redisClient: ReturnType<typeof import('./utils').getRedisConnection>,
|
||||||
logger?: any
|
logger?: Logger
|
||||||
) {
|
) {
|
||||||
this.logger = logger || console;
|
this.logger = logger || console;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,14 +51,12 @@ describe('QueueManager', () => {
|
||||||
describe('Basic Operations', () => {
|
describe('Basic Operations', () => {
|
||||||
test('should initialize queue manager', async () => {
|
test('should initialize queue manager', async () => {
|
||||||
queueManager = new QueueManager({
|
queueManager = new QueueManager({
|
||||||
queueName: 'test-queue',
|
|
||||||
redis: redisConfig,
|
redis: redisConfig,
|
||||||
workers: 1,
|
|
||||||
concurrency: 5,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await queueManager.initialize();
|
// No need to initialize anymore - constructor handles everything
|
||||||
expect(queueManager.queueName).toBe('test-queue');
|
// QueueManager now manages multiple queues, not just one
|
||||||
|
expect(queueManager).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should add and process a job', async () => {
|
test('should add and process a job', async () => {
|
||||||
|
|
@ -73,15 +71,17 @@ describe('QueueManager', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
queueManager = new QueueManager({
|
queueManager = new QueueManager({
|
||||||
queueName: 'test-queue',
|
|
||||||
redis: redisConfig,
|
redis: redisConfig,
|
||||||
|
});
|
||||||
|
|
||||||
|
// No need to initialize anymore - constructor handles everything
|
||||||
|
// Get or create a queue
|
||||||
|
const queue = queueManager.getQueue('test-queue', {
|
||||||
workers: 1,
|
workers: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
await queueManager.initialize();
|
|
||||||
|
|
||||||
// Add job
|
// Add job
|
||||||
const job = await queueManager.add('test-job', {
|
const job = await queue.add('test-job', {
|
||||||
handler: 'test-handler',
|
handler: 'test-handler',
|
||||||
operation: 'test-operation',
|
operation: 'test-operation',
|
||||||
payload: { message: 'Hello, Queue!' },
|
payload: { message: 'Hello, Queue!' },
|
||||||
|
|
@ -102,7 +102,7 @@ describe('QueueManager', () => {
|
||||||
workers: 1,
|
workers: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
await queueManager.initialize();
|
// No need to initialize anymore - constructor handles everything
|
||||||
|
|
||||||
const job = await queueManager.add('test-job', {
|
const job = await queueManager.add('test-job', {
|
||||||
handler: 'non-existent',
|
handler: 'non-existent',
|
||||||
|
|
@ -134,7 +134,7 @@ describe('QueueManager', () => {
|
||||||
concurrency: 5,
|
concurrency: 5,
|
||||||
});
|
});
|
||||||
|
|
||||||
await queueManager.initialize();
|
// No need to initialize anymore - constructor handles everything
|
||||||
|
|
||||||
const jobs = await queueManager.addBulk([
|
const jobs = await queueManager.addBulk([
|
||||||
{
|
{
|
||||||
|
|
@ -166,7 +166,7 @@ describe('QueueManager', () => {
|
||||||
workers: 0, // No workers, jobs will stay in waiting
|
workers: 0, // No workers, jobs will stay in waiting
|
||||||
});
|
});
|
||||||
|
|
||||||
await queueManager.initialize();
|
// No need to initialize anymore - constructor handles everything
|
||||||
|
|
||||||
// Add some jobs
|
// Add some jobs
|
||||||
await queueManager.add('job1', {
|
await queueManager.add('job1', {
|
||||||
|
|
@ -205,7 +205,7 @@ describe('QueueManager', () => {
|
||||||
workers: 1,
|
workers: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
await queueManager.initialize();
|
// No need to initialize anymore - constructor handles everything
|
||||||
|
|
||||||
// Pause queue
|
// Pause queue
|
||||||
await queueManager.pause();
|
await queueManager.pause();
|
||||||
|
|
@ -260,7 +260,7 @@ describe('QueueManager', () => {
|
||||||
enableScheduledJobs: true,
|
enableScheduledJobs: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await queueManager.initialize();
|
// No need to initialize anymore - constructor handles everything
|
||||||
|
|
||||||
// Wait for scheduled job to execute
|
// Wait for scheduled job to execute
|
||||||
await new Promise(resolve => setTimeout(resolve, 2500));
|
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', {
|
const job = await queueManager.add('retry-job', {
|
||||||
handler: 'retry-handler',
|
handler: 'retry-handler',
|
||||||
|
|
@ -341,7 +341,7 @@ describe('QueueManager', () => {
|
||||||
workers: 2,
|
workers: 2,
|
||||||
});
|
});
|
||||||
|
|
||||||
await queueManager.initialize();
|
// No need to initialize anymore - constructor handles everything
|
||||||
|
|
||||||
// Add jobs for different handlers
|
// Add jobs for different handlers
|
||||||
await queueManager.addBulk([
|
await queueManager.addBulk([
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue