UNPKG

torotask

Version:

Task queue processing in NodeJS based on BullMQ and Redis

38 lines 2.04 kB
import type { Logger } from 'pino'; import type { Task } from './task.js'; import type { SubTaskHandler, TaskJobData, TaskJobOptions } from './types/index.js'; import { TaskJob } from './job.js'; /** * Represents a defined SubTask within a parent Task. * Provides methods to enqueue jobs specifically for this subtask's handler, * utilizing the parent Task's queue. * * @template DataType The expected type of the data payload for this subtask. * @template ResultType The expected return type of the job associated with this subtask. */ export declare class SubTask<PayloadType = any, ResultType = unknown, const DataType extends TaskJobData = TaskJobData<PayloadType>> { readonly parentTask: Task<any, any>; readonly id: string; readonly handler: SubTaskHandler<PayloadType, ResultType>; readonly logger: Logger; constructor(parentTask: Task<any, any>, id: string, handler: SubTaskHandler<PayloadType, ResultType>); /** * Adds a job to the parent task's queue, specifically targeting this subtask's handler. * * @param data The data payload for the job. * @param overrideOptions Optional JobOptions to override the parent task's defaults. * @returns A promise resolving to the enqueued BullMQ Job object. */ run(payload: PayloadType, overrideOptions?: TaskJobOptions): Promise<TaskJob<any, any, string, TaskJobData<any>, import("./types/job.js").TaskJobState>>; processSubJob(job: TaskJob<PayloadType, ResultType>, jobName: string, jobLogger: Logger): Promise<any>; /** * Adds a job for this subtask and waits for it to complete. * * @param data The data payload for the job. * @param overrideOptions Optional JobOptions to override the parent task's defaults. * @returns A promise resolving to the return value of the completed job. * @throws Throws an error if the job fails or cannot be awaited. */ runAndWait(data: DataType, overrideOptions?: TaskJobOptions): Promise<ResultType>; } //# sourceMappingURL=sub-task.d.ts.map