UNPKG

torotask

Version:

Task queue processing in NodeJS based on BullMQ and Redis

49 lines 2.52 kB
import type { JobsOptions, WorkerOptions } from 'bullmq'; import type { Logger } from 'pino'; import type { ToroTask } from './client.js'; import type { TaskJob } from './job.js'; import type { EventQueueOptions, EventSubscriptionInfo, SyncJobPayload, SyncJobReturn, TaskJobOptions } from './types/index.js'; import { EventSubscriptions } from './event-subscriptions.js'; import { TaskWorkerQueue } from './worker-queue.js'; type PayloadType = SyncJobPayload; type ReturnType = SyncJobReturn; /** * Manages the synchronization of event trigger registrations using a dedicated queue * processed by a single worker. Ensures atomic updates across multiple Task instances. * Uses EventSubscriptionRepository for persistence. */ export declare class EventManager extends TaskWorkerQueue<PayloadType, ReturnType> { readonly subscriptions: EventSubscriptions; readonly prefix: string; /** Default job options for sync jobs */ readonly eventDefaultJobOptions: Partial<JobsOptions>; /** Worker options for this queue */ readonly eventWorkerOptions: Partial<WorkerOptions>; constructor(taskClient: ToroTask, // Accept ToroTask parentLogger: Logger, name?: string, prefix?: string, subscriptions?: EventSubscriptions, // Allow injecting subscriptions eventQueueOptions?: EventQueueOptions); /** * Overrides BaseQueue's startWorker with concurrency option */ getWorkerOptions(): Partial<WorkerOptions>; /** * Adds a job to the synchronization queue to update event registrations for a specific task. * Uses a job ID based on the task to prevent duplicate concurrent syncs. * * @param taskGroup The group name of the task. * @param taskId The id of the task. * @param desiredSubscriptions The complete list of event subscriptions the task should have. * @param options Optional BullMQ job options. */ requestSync(taskGroup: string, taskId: string, desiredSubscriptions: EventSubscriptionInfo[], options?: TaskJobOptions): Promise<TaskJob<PayloadType, ReturnType, string>>; /** * Processes a synchronization job. Fetches current Redis state via the repository, * compares with desired state from the job payload, and calls repository methods * to register/unregister differences. Executed by the single worker. * * @param job The synchronization job. */ process(job: TaskJob<PayloadType, ReturnType, string>): Promise<ReturnType>; } export {}; //# sourceMappingURL=event-manager.d.ts.map