UNPKG

torotask

Version:

Task queue processing in NodeJS based on BullMQ and Redis

119 lines 5.05 kB
import { Job, JobsOptions, MinimalQueue } from 'bullmq'; import { Logger } from 'pino'; import type { TaskJobData, TaskJobOptions, TaskJobState } from './types/index.js'; import { TaskQueue } from './queue.js'; import { ToroTask } from './client.js'; export declare class TaskJob<PayloadType = any, ReturnType = any, NameType extends string = string, const DataType extends TaskJobData = TaskJobData<PayloadType>, const StateType = TaskJobState> extends Job<DataType, ReturnType, NameType> { options: TaskJobOptions<DataType>; logger?: Logger; taskClient?: ToroTask; taskQueue?: TaskQueue; /** * The array of real TaskJob instances that constitute a batch. */ private batch; payload: PayloadType; state: StateType; opts: JobsOptions; constructor(queue: MinimalQueue, name: NameType, data: DataType, options?: TaskJobOptions<DataType>, id?: string); /** * Sets a job's payload * * @param payload - the payload that will replace the current jobs payload. */ setPayload(payload: PayloadType): Promise<void>; /** * Partially updates a job's payload * * @param payload - the payload that will merge with the current jobs payload. */ updatePayload(payload: Partial<PayloadType>): Promise<void>; /** * Sets a job's state * * @param state - the state that will replace the current jobs state. */ setState(state: StateType): Promise<void>; /** * Partially updates a job's state * * @param state - the state that will merge with the current jobs state. */ updateState(state: Partial<StateType>): Promise<void>; /** * Sets/replaces the internal list of Job instances managed by this container. * @param jobs The array of Job instances representing the batch. */ setBatch(batch: (typeof this)[]): void; /** * Adds a single job to the internal list for this batch container. * @param job The job to add. */ addBatchJob(job: typeof this): void; /** * Adds multiple jobs to the internal list for this batch container. * @param jobs The jobs to add. */ addBatchJobs(jobs: (typeof this)[]): void; /** * Returns the array of actual TaskJob instances managed by this batch container. * @returns The array of jobs. */ getBatch(): (typeof this)[]; /** * Returns the array of actual TaskJob instances managed by this batch container. * @returns The array of jobs. */ get isBatch(): boolean; /** * Returns the number of jobs currently in the batch. * @returns The number of jobs. */ get batchLength(): number; /** * **Manual Lock Extension:** Extends the lock for all individual jobs currently held within this batch container. * * **Usage Note:** Generally **not required**. Rely on the Worker's automatic lock renewal * by configuring `lockDuration` appropriately. Use this only for explicit manual control * during very long-running steps within your handler. * * @param duration - Duration (in milliseconds) to extend the lock by. Uses the job's configured lock duration if omitted. * @returns A promise that resolves when all lock extensions have been attempted. */ extendLocks(duration: number): Promise<void>; /** * Updates the progress for all individual jobs currently held within this batch container. * * @param progress The progress value (number or object). * @returns A promise that resolves when all progress updates have been attempted. */ updateProgress(progress: number | object): Promise<void>; /** * Sends the same log entry to all individual jobs currently held within this batch container * using the underlying `job.log()` method. * * @param logRow The string log entry to add to each job's log in Redis. * @returns A promise that resolves when all log additions have been attempted. */ log(logRow: string): Promise<number>; /** * Clears all batched job's logs * * @param keepLogs - the amount of log entries to preserve */ clearLogs(keepLogs?: number): Promise<void>; /** * Attempts to move all individual jobs currently held within this batch container to the 'failed' state in BullMQ. * * **Use Case:** Useful if you detect a non-recoverable error *within* your batch handler * and want to explicitly mark all jobs as failed *before* throwing an error to signal the overall batch failure. * Often, just throwing an error from the handler is sufficient. * * **Requires Job Tokens:** This operation requires the lock `token` for each individual job. * * @param error The Error object representing the reason for failure. * @returns A promise that resolves when all `moveToFailed` operations have been attempted. */ moveToFailed(error: Error, token: string, fetchNext?: boolean): Promise<void | any[]>; } //# sourceMappingURL=job.d.ts.map