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.
70 lines (69 loc) • 2.33 kB
TypeScript
import { IStateStorageAdapter, ITask, TaskStatus, TaskQueryOptions } from '../interfaces/storage-adapter.interface';
/**
* MongoDB storage adapter options
*/
export interface MongoStorageOptions {
uri: string;
collectionName?: string;
options?: any;
}
/**
* MongoDB storage adapter
*/
export declare class MongoStorageAdapter implements IStateStorageAdapter {
private options;
private connection;
private TaskModel;
private UniquenessModel;
private RateLimitModel;
private collectionName;
constructor(options: MongoStorageOptions);
initialize(): Promise<void>;
saveTask(task: ITask): Promise<void>;
getTask(taskId: string): Promise<ITask | null>;
updateTaskStatus(taskId: string, status: TaskStatus, updateData?: Partial<ITask>): Promise<void>;
/**
* Delete a task
*/
deleteTask(taskId: string): Promise<boolean>;
getTasks(options?: TaskQueryOptions): Promise<ITask[]>;
getTaskCount(options?: TaskQueryOptions): Promise<number>;
isUniquenessKeyActive(key: string): Promise<boolean>;
setUniquenessKeyActive(key: string, taskId: string, ttlSeconds?: number): Promise<void>;
removeUniquenessKey(key: string): Promise<void>;
getRateLimit(key: string): Promise<{
count: number;
resetTime: Date;
} | null>;
incrementRateLimit(key: string, windowMs: number, maxRequests: number): Promise<{
allowed: boolean;
count: number;
resetTime: Date;
}>;
deleteRateLimit(key: string): Promise<void>;
hasActiveTaskInChain(chainId: string): Promise<boolean>;
getNextChainIndex(chainId: string): Promise<number>;
cleanup(options?: {
olderThan?: Date;
statuses?: TaskStatus[];
removeCompleted?: boolean;
removeFailed?: boolean;
}): Promise<number>;
close(): Promise<void>;
/**
* Clear all tasks - for testing purposes only
*/
private clearAllTasks;
/**
* Get all tasks in a chain
*/
getChainTasks(chainId: string): Promise<ITask[]>;
/**
* Get the next task in a chain after the current step
*/
getNextTaskInChain(chainId: string, currentStep: number): Promise<ITask | null>;
/**
* Create a new task (alias for saveTask)
*/
createTask(task: ITask): Promise<ITask>;
}