UNPKG

nodejs-cloud-taskmq

Version:

Node.js TypeScript library for integrating Google Cloud Tasks with MongoDB/Redis/Memory/Custom for a BullMQ-like queue system. Compatible with NestJS but framework-agnostic.

111 lines (110 loc) 2.58 kB
import { ITask, TaskStatus } from '../interfaces/storage-adapter.interface'; import { TaskProgress } from '../interfaces/task.interface'; /** * CloudTask model representing a task in the queue system */ export declare class CloudTask<T = any> { readonly id: string; readonly queueName: string; readonly data: T; status: TaskStatus; readonly createdAt: Date; updatedAt: Date; completedAt?: Date; failedAt?: Date; attempts: number; readonly maxAttempts: number; error?: { message: string; stack?: string; timestamp: Date; }; progress?: { percentage: number; data?: any; }; result?: any; readonly delay?: number; readonly scheduledFor?: Date; readonly chain?: { id: string; index: number; total: number; }; readonly uniquenessKey?: string; readonly options?: { removeOnComplete?: boolean; removeOnFail?: boolean; priority?: number; [key: string]: any; }; constructor(task: ITask); /** * Update task progress */ updateProgress(progress: TaskProgress): void; /** * Mark task as active */ markAsActive(): void; /** * Mark task as completed */ markAsCompleted(result?: any): void; /** * Mark task as failed */ markAsFailed(error: Error | string): void; /** * Increment attempt counter */ incrementAttempts(): void; /** * Check if task has exceeded maximum attempts */ hasExceededMaxAttempts(): boolean; /** * Check if task is in a chain */ isInChain(): boolean; /** * Check if task is the first in chain */ isFirstInChain(): boolean; /** * Check if task is the last in chain */ isLastInChain(): boolean; /** * Get next task index in chain */ getNextChainIndex(): number | null; /** * Check if task should be removed on completion */ shouldRemoveOnComplete(): boolean; /** * Check if task should be removed on failure */ shouldRemoveOnFail(): boolean; /** * Get task priority */ getPriority(): number; /** * Get task age in milliseconds */ getAge(): number; /** * Get task duration (if completed or failed) */ getDuration(): number | null; /** * Convert to plain object */ toObject(): ITask; /** * Create CloudTask from plain object */ static fromObject<T = any>(obj: ITask): CloudTask<T>; }