UNPKG

torotask

Version:

Task queue processing in NodeJS based on BullMQ and Redis

43 lines 3.08 kB
import type { Logger } from 'pino'; import { BaseTask } from './base-task.js'; import { SubTask } from './sub-task.js'; import type { TaskGroup } from './task-group.js'; import type { EffectivePayloadType, ResolvedSchemaType, SubTaskHandler, TaskConfig, TaskHandler, TaskOptions, TaskJobData, SchemaHandler } from './types/index.js'; import { TaskJob } from './job.js'; /** * Represents a defined task associated with a TaskGroup. * Extends BaseTask to manage its own underlying BullMQ queue and worker. * Implements the `process` method by calling the specific task `handler` or a registered subtask handler. * Can define and manage SubTasks. * * @template PayloadExplicit The explicitly provided payload type. Defaults to `unknown`. * If not `unknown`, this type takes precedence. * If `unknown`, type is inferred from `Schema` or defaults to `any`. * @template ResultType The expected return type of the job. Defaults to `unknown`. * @template SchemaInputVal The input schema type for payload validation and type inference. Defaults to `undefined`. */ export declare class Task<PayloadExplicit = unknown, // Default changed to unknown ResultType = unknown, SchemaInputVal extends SchemaHandler = undefined, // Task is generic over INPUT schema type ActualPayloadType extends EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>> = EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>> extends BaseTask<ActualPayloadType, ResultType, TaskJobData<ActualPayloadType>, TaskOptions> { /** * A type-only property to help infer the actual payload type of the task. * This is equivalent to EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>. */ readonly _payloadType: ActualPayloadType; /** * A type-only property to help infer the result type of the task. */ readonly _resultType: ResultType; protected readonly subTasks: Map<string, SubTask<any, any>>; protected readonly allowCatchAll: boolean; protected handler: TaskHandler<ActualPayloadType, ResultType, ResolvedSchemaType<SchemaInputVal>>; readonly schema: ResolvedSchemaType<SchemaInputVal>; constructor(taskGroup: TaskGroup, id: string, config: TaskConfig<PayloadExplicit, ResultType, SchemaInputVal>, groupLogger: Logger); defineSubTask<SubTaskPayloadType = ActualPayloadType, // Default SubTask payload to parent's effective type SubTaskResultType = ResultType>(subTaskId: string, subTaskHandler: SubTaskHandler<SubTaskPayloadType, SubTaskResultType>): SubTask<SubTaskPayloadType, SubTaskResultType>; getSubTask(subTaskId: string): SubTask<any, any> | undefined; process(job: TaskJob<ActualPayloadType, ResultType>, token?: string): Promise<ResultType>; validateJob(job: TaskJob<ActualPayloadType, ResultType>, jobLogger?: Logger): Promise<ActualPayloadType>; processJob(job: TaskJob<ActualPayloadType, ResultType>, token?: string, jobLogger?: Logger): Promise<ResultType>; } //# sourceMappingURL=task.d.ts.map