UNPKG

torotask

Version:

Task queue processing in NodeJS based on BullMQ and Redis

75 lines 3.65 kB
import type { Redis } from 'ioredis'; import type { Logger } from 'pino'; import type { EventSubscriptionInfo } from './types/index.js'; /** * Manages the persistence of event subscriptions in Redis. * Encapsulates all direct Redis interactions related to event subscriptions. */ export declare class EventSubscriptions { private readonly redis; private readonly logger; readonly prefix: string; constructor(redisClient: Redis, prefix: string, logger: Logger); /** * Generates the Redis key for storing subscriptions for a specific event. * Matches the original EventManager logic. * @param eventName - The name of the event. * @returns The Redis key string. */ getEventKey(eventName: string): string; /** * Gets the Redis key for the Set containing event names a task is subscribed to. * @param taskGroup Task group name. * @param taskId Task id. * @returns The Redis key string. */ getTaskIndexKey(taskGroup: string, taskId: string): string; /** * Generates a unique identifier string for a subscription to be used as a field key in Redis Hashes. * @param info The EventSubscriptionInfo object. * @returns A string identifier (e.g., "group:task:trigger:123" or "group:task:event:abc"). */ getIdentifier(info: EventSubscriptionInfo): string; /** * Registers a new event subscription in Redis. * Adds the subscription details to the event's hash and adds the event name to the task's index set. * Matches the original EventManager.registerTaskEvent logic. * @param eventName - The name of the event to subscribe to. * @param info - The subscription information. * @returns A promise resolving when the registration is complete. */ register(eventName: string, info: EventSubscriptionInfo): Promise<void>; /** * Unregisters an event subscription from Redis. * Removes the subscription details from the event's hash and potentially removes the event * from the task's index set if no other subscriptions for that task remain for the event. * Matches the original EventManager.unregisterTaskEvent logic. * @param eventName - The name of the event to unsubscribe from. * @param info - The subscription information to remove. * @returns A promise resolving when the unregistration is complete. */ unregister(eventName: string, info: EventSubscriptionInfo): Promise<void>; /** * Retrieves all subscriptions associated with a specific task by querying its index * and then fetching the details from the relevant event keys. * Matches the original logic from EventManager.process for fetching current state. * @param taskGroup - The group of the task. * @param taskId - The id of the task. * @returns A promise resolving to an array of subscription information objects. */ getForTask(taskGroup: string, taskId: string): Promise<EventSubscriptionInfo[]>; /** * Retrieves all subscriptions registered for a specific event. * @param eventName - The name of the event. * @returns A promise resolving to an array of subscription information objects. */ getForEvent(eventName: string): Promise<EventSubscriptionInfo[]>; /** * Retrieves the set of event names a specific task is subscribed to. * @param taskGroup - The group of the task. * @param taskId - The id of the task. * @returns A promise resolving to an array of event names. */ getTaskEventIndex(taskGroup: string, taskId: string): Promise<string[]>; } //# sourceMappingURL=event-subscriptions.d.ts.map