queue-manager-pro
Version:
A flexible, TypeScript-first queue/task manager with pluggable backends ,dynamic persistence storage and event hooks.
57 lines (56 loc) • 2.85 kB
TypeScript
import { type HandlerOptions } from './handlerRegistry.js';
import { type EmitMethod, type HandlerMap, type IQueueManager, type QueueBackendConfig, type QueueManagerEvents, type Task } from '../types/index.js';
export declare class QueueManager<H extends HandlerMap> {
private readonly emitter;
private static instance;
private readonly delay;
private readonly registry;
private readonly repository;
private readonly MAX_RETRIES;
private readonly MAX_PROCESSING_TIME;
backend: QueueBackendConfig;
private readonly worker;
crashOnWorkerError: boolean;
private readonly logger;
on<K extends keyof QueueManagerEvents<H>>(event: K, listener: QueueManagerEvents<H>[K]): this;
emit: EmitMethod;
private constructor();
static getInstance<H extends HandlerMap>(args: Omit<IQueueManager, 'repository'>): QueueManager<H>;
private static getBackendRepository;
addTaskToQueue<K extends keyof H>(handler: K, payload: Parameters<H[K]>[0], options?: {
maxRetries?: Task<HandlerMap>['maxRetries'];
maxProcessingTime?: Task<HandlerMap>['maxProcessingTime'];
priority?: Task<HandlerMap>['priority'];
skipOnPayloadError?: boolean;
}, extraTaskProps?: Record<string, any>): Promise<Task<H>>;
removeTask(id: number, hardDelete?: boolean): Promise<Task<H> | undefined>;
updateTask(id: Task<HandlerMap>['id'], obj: Partial<Task<HandlerMap>>): Promise<Task<HandlerMap> | undefined>;
getAllTasks(status?: Task<HandlerMap>['status']): Promise<Task<H>[]>;
getTaskById(id: string): Promise<Task<H> | undefined>;
startWorker(concurrency?: number): Promise<void>;
stopWorker(): Promise<void>;
/**
* Register a handler for a specific task type.
* This method registers a handler function for a specific task type,
* allowing the queue manager to execute the handler when a task of that type is dequeued.
* @param name The name of the handler
* @param handler The function to execute for this handler
* @param options Optional parameters for max retries and processing time
*/
register<K extends keyof H>(name: K, handler: H[K], options?: HandlerOptions<Parameters<H[K]>[0]>): void;
/**
* Get the registered handler for a specific task type.
* This method retrieves the handler function and its parameters for a specific task type.
* - useful for validating payloads before adding tasks to the queue.
* @param name The name of the handler
* @returns An object containing the handler function and its parameters
*/
validateHandlerParams(name: string, payload: any): {
isValid: boolean;
message: string | null;
source: "auto-schema" | "param-schema" | null;
};
private log;
runMigration(): Promise<void>;
}
export default QueueManager;