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.
78 lines (77 loc) • 2.3 kB
TypeScript
import 'reflect-metadata';
/**
* Metadata keys for event decorators
*/
export declare const EVENT_HANDLERS_KEY = "cloud_taskmq:event_handlers";
/**
* Event handler metadata
*/
export interface EventHandlerMetadata {
event: string;
methodName: string;
handler: Function;
}
/**
* Decorator for handling task active events.
* This method will be called when a task becomes active.
*
* @example
* ```typescript
* @Processor('email-queue')
* export class EmailProcessor {
* @OnTaskActive()
* async onTaskActive(task: CloudTask<EmailData>) {
* console.log(`Task ${task.id} is now active`);
* }
* }
* ```
*/
export declare function OnTaskActive(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
/**
* Decorator for handling task completed events.
* This method will be called when a task completes successfully.
*
* @example
* ```typescript
* @Processor('email-queue')
* export class EmailProcessor {
* @OnTaskCompleted()
* async onTaskCompleted(task: CloudTask<EmailData>, result: any) {
* console.log(`Task ${task.id} completed with result:`, result);
* }
* }
* ```
*/
export declare function OnTaskCompleted(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
/**
* Decorator for handling task failed events.
* This method will be called when a task fails.
*
* @example
* ```typescript
* @Processor('email-queue')
* export class EmailProcessor {
* @OnTaskFailed()
* async onTaskFailed(task: CloudTask<EmailData>, error: Error) {
* console.error(`Task ${task.id} failed:`, error);
* }
* }
* ```
*/
export declare function OnTaskFailed(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
/**
* Decorator for handling task progress events.
* This method will be called when a task reports progress.
*
* @example
* ```typescript
* @Processor('email-queue')
* export class EmailProcessor {
* @OnTaskProgress()
* async onTaskProgress(task: CloudTask<EmailData>, progress: { percentage: number; data?: any }) {
* console.log(`Task ${task.id} progress: ${progress.percentage}%`);
* }
* }
* ```
*/
export declare function OnTaskProgress(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;