UNPKG

torotask

Version:

Task queue processing in NodeJS based on BullMQ and Redis

40 lines 3.28 kB
import type { Logger } from 'pino'; import type { TaskJob } from './job.js'; import type { TaskGroup } from './task-group.js'; import type { EffectivePayloadType, ResolvedSchemaType, SchemaHandler, SubTaskHandler, TaskConfig, TaskHandler, TaskJobData, TaskOptions } from './types/index.js'; import { BaseTask } from './base-task.js'; import { SubTask } from './sub-task.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, ResultType = unknown, SchemaInputVal extends SchemaHandler = undefined> extends BaseTask<EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>, ResultType, TaskJobData<EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>>, 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: EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>; /** * 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<EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>, ResultType, ResolvedSchemaType<SchemaInputVal>>; readonly schema: ResolvedSchemaType<SchemaInputVal>; constructor(taskGroup: TaskGroup, id: string, config: TaskConfig<PayloadExplicit, ResultType, SchemaInputVal>, groupLogger: Logger); defineSubTask<SubTaskPayloadType = EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>, SubTaskResultType = ResultType>(subTaskId: string, subTaskHandler: SubTaskHandler<SubTaskPayloadType, SubTaskResultType>): SubTask<SubTaskPayloadType, SubTaskResultType>; getSubTask(subTaskId: string): SubTask<any, any> | undefined; process(job: TaskJob<EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>, ResultType>, token?: string): Promise<ResultType>; validateJob(job: TaskJob<EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>, ResultType>, jobLogger?: Logger): Promise<EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>>; processJob(job: TaskJob<EffectivePayloadType<PayloadExplicit, ResolvedSchemaType<SchemaInputVal>>, ResultType>, token?: string, jobLogger?: Logger): Promise<ResultType>; } //# sourceMappingURL=task.d.ts.map