torotask
Version:
Task queue processing in NodeJS based on BullMQ and Redis
58 lines • 2.9 kB
TypeScript
import type { Job } from 'bullmq';
import { Worker } from 'bullmq';
import type { Logger } from 'pino';
import type { ToroTask } from './client.js';
import type { TaskWorkerOptions, TaskProcessor, TaskValidator, TaskJobData } from './types/index.js';
import { TaskJob } from './job.js';
export declare class TaskWorker<PayloadType = any, ResultType = unknown, NameType extends string = string, const JobType extends TaskJob<PayloadType, ResultType, NameType> = TaskJob<PayloadType, ResultType, NameType>> extends Worker<TaskJobData<PayloadType>, ResultType, NameType> {
readonly taskClient: ToroTask;
protected validator?: (null | TaskValidator<PayloadType, ResultType, NameType>) | undefined;
readonly logger: Logger;
private readonly isBatchingEnabled;
readonly options: Partial<TaskWorkerOptions>;
private jobBatch;
private jobBatchCreationTime;
private jobBatchProcessPromise;
private resolveJobBatchProcessPromise;
private rejectJobBatchProcessPromise;
private batchProcessingRunning;
private batchTimeoutTimer;
private batchLock;
private batchProcessingScheduled;
constructor(taskClient: ToroTask, name: string, processor?: string | URL | null | TaskProcessor<PayloadType, ResultType, NameType>, validator?: (null | TaskValidator<PayloadType, ResultType, NameType>) | undefined, options?: Partial<TaskWorkerOptions>);
static validateBatchOptions(name: string, options: Partial<TaskWorkerOptions>, logger?: Logger): Partial<TaskWorkerOptions>;
protected callValidateJob(job: TaskJob<PayloadType, ResultType, NameType>): Promise<PayloadType | undefined>;
/**
* If batching is enabled, this method is called to process a job.
* Adds the job to the current batch, manages the timeout timer, triggers
* processing if size limit is reached, and awaits batch completion.
*
* @override
* @param job - The standard BullMQ job object.
* @returns A promise that resolves/rejects when the batch containing this job completes/fails.
*/
protected callProcessJob(job: TaskJob<any, ResultType, NameType>, token: string): Promise<ResultType>;
/**
* The processor function used by BullMQ Worker when batching is enabled.
* Collects jobs into a batch and triggers processing.
*/
private batchJobCollector;
private initializeJobBatch;
private clearBatchTimeoutTimer;
private startBatchTimeoutTimerIfNeeded;
private processBatchWrapper;
/**
* Gracefully shuts down the worker.
* Handles final batch processing if enabled.
*
* @override
*/
close(force?: boolean): Promise<void>;
/**
* Override the Job class to use TaskJob
* @returns {typeof Job}
*/
protected get Job(): typeof Job;
protected get TaskJob(): typeof TaskJob<PayloadType, ResultType, NameType>;
}
//# sourceMappingURL=worker.d.ts.map