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.

40 lines (39 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PROCESS_METADATA_KEY = void 0; exports.Process = Process; require("reflect-metadata"); /** * Metadata key for process decorators */ exports.PROCESS_METADATA_KEY = 'cloud_taskmq:process_metadata'; /** * Marks a method as a task processor. * This method will be called to process tasks from the queue. * * @param options Process options * * @example * ```typescript * @Processor('email-queue') * export class EmailProcessor { * @Process({ name: 'send-email' }) * async handleEmailTask(job: CloudTask<EmailData>) { * // Process the email task * return { success: true }; * } * } * ``` */ function Process(options = {}) { return (target, propertyKey, descriptor) => { const existingProcesses = Reflect.getMetadata(exports.PROCESS_METADATA_KEY, target) || []; existingProcesses.push({ methodName: propertyKey, name: options.name || propertyKey, concurrency: options.concurrency, handler: descriptor.value, }); Reflect.defineMetadata(exports.PROCESS_METADATA_KEY, existingProcesses, target); }; }