@clipwhisperer/common
Version:
ClipWhisperer Common - Shared library providing core utilities, database schemas, authentication, bucket management, and common functionality across all ClipWhisperer microservices
94 lines (93 loc) • 2.81 kB
TypeScript
/**
* Queue Infrastructure
* Centralized BullMQ queue and worker management
*/
import { Queue, Worker, Job } from "bullmq";
import { PerformanceTracker } from "./performance";
export type QueueJobInput = Record<string, any>;
export type QueueJobOutput = Record<string, any>;
export interface QueueConfig {
name: string;
connection?: {
host: string;
port: number;
};
defaultJobOptions?: {
removeOnComplete?: boolean;
removeOnFail?: boolean;
attempts?: number;
backoff?: {
type: string;
delay: number;
};
};
}
/**
* Queue Factory - Creates standardized BullMQ queues
*/
export declare class QueueFactory {
/**
* Create a queue with standard configuration
*/
static createQueue<TInput extends QueueJobInput, TOutput extends QueueJobOutput>(queueName: string, config?: Partial<QueueConfig>): Queue<TInput, TOutput>;
/**
* Create a worker with standard configuration
*/
static createWorker<TInput extends QueueJobInput, TOutput extends QueueJobOutput>(queueName: string, processor: (job: Job<TInput, TOutput>) => Promise<TOutput>, config?: Partial<QueueConfig>): Worker<TInput, TOutput>;
}
/**
* Base Queue Manager - Provides common queue operations
*/
export declare abstract class BaseQueueManager<TInput extends QueueJobInput, TOutput extends QueueJobOutput> {
protected queueName: string;
protected config?: Partial<QueueConfig>;
protected queue: Queue<TInput, TOutput>;
protected worker?: Worker<TInput, TOutput>;
protected performanceTracker: PerformanceTracker;
constructor(queueName: string, config?: Partial<QueueConfig>);
/**
* Add a job to the queue
*/
addJob(jobName: string, data: TInput, options?: {
removeOnComplete?: boolean;
removeOnFail?: boolean;
delay?: number;
attempts?: number;
}): Promise<{
jobId: string;
}>;
/**
* Start the worker
*/
startWorker(processor: (job: Job<TInput, TOutput>) => Promise<TOutput>): void;
/**
* Get queue statistics
*/
getQueueStats(): Promise<{
waiting: number;
active: number;
completed: number;
failed: number;
}>;
/**
* Get enhanced performance metrics including queue size
*/
getPerformanceMetrics(): Promise<{
queueSize: number;
queueStats: {
waiting: number;
active: number;
completed: number;
failed: number;
};
totalRequests: number;
averageResponseTime: number;
successRate: number;
memoryUsage: NodeJS.MemoryUsage;
uptime: number;
}>;
/**
* Close queue and worker connections
*/
close(): Promise<void>;
}