import { Log } from 'ts-tiny-log'; import { TaskPersistence } from './task-persistence'; import { Task } from './task'; import { Worker } from './worker'; import { Pool } from './pool'; import { QueueOptions } from './queue'; export interface DispatcherConfig { /** * Queue name. Must be unique */ name: string; /** * Worker entry file. Must be a relative/absolute path/file */ workerEntry: string; /** * Number of workers */ nWorkers: number; /** * Worker class type */ workerType: typeof Worker; /** * Error handler */ error?: (err: Error) => void | Promise; /** * Queue options for retry and polling */ options: QueueOptions; } /** * QueueDispatcher class - handles task distribution on the main thread * * @typeParam TIn Queue task input type * @typeParam TOut Queue task output type */ export declare class QueueDispatcher { protected log: Log; protected tasks: TaskPersistence; protected pool: Pool; protected config: DispatcherConfig; /** * Runs on: Main * * @param tasks Task persistence instance * @param config Dispatcher configuration */ constructor(tasks: TaskPersistence, config: DispatcherConfig); /** * Initialize the dispatcher by setting up the worker pool * * Runs on: Main */ initialize(): Promise; /** * Start the polling loop to distribute tasks to workers * * Runs on: Main */ start(): void; /** * Apply retry handling to a task's reject callback * * Runs on: Main * * @param task Task to apply retry handler to */ protected applyRetryHandler(task: Task): void; /** * Check if a task has expired * * Runs on: Main * * @param task Task to check * @return Returns true if the task has expired, false otherwise */ protected isTaskExpired(task: Task): boolean; }