@hotmeshio/hotmesh
Version:
Permanent-Memory Workflows & AI Agents
60 lines (59 loc) • 2.56 kB
TypeScript
import { ILogger } from '../../../logger';
import { PostgresClientType } from '../../../../types/postgres';
import { NotificationConsumer, StreamMessage } from '../../../../types/stream';
import { ProviderClient } from '../../../../types/provider';
/**
* Manages PostgreSQL LISTEN/NOTIFY for stream message notifications.
* Handles static state shared across all service instances using the same client.
*/
export declare class NotificationManager<TService> {
private client;
private getTableName;
private getFallbackInterval;
private logger;
private static clientNotificationConsumers;
private static clientNotificationHandlers;
private static clientFallbackPollers;
private instanceNotificationConsumers;
private notificationHandlerBound;
constructor(client: PostgresClientType & ProviderClient, getTableName: () => string, getFallbackInterval: () => number, logger: ILogger);
/**
* Set up notification handler for this client (once per client).
*/
setupClientNotificationHandler(serviceInstance: TService): void;
/**
* Start fallback poller for missed notifications (once per client).
*/
startClientFallbackPoller(checkForMissedMessages: () => Promise<void>): void;
/**
* Check for missed messages (fallback polling).
* Handles errors gracefully to avoid noise during shutdown.
*/
checkForMissedMessages(fetchMessages: (instance: TService, consumer: NotificationConsumer) => Promise<StreamMessage[]>): Promise<void>;
/**
* Handle incoming PostgreSQL notification.
*/
private handleNotification;
/**
* Set up notification consumer for a stream/group.
*/
setupNotificationConsumer(serviceInstance: TService, streamName: string, groupName: string, consumerName: string, callback: (messages: StreamMessage[]) => void): Promise<void>;
/**
* Stop notification consumer for a stream/group.
*/
stopNotificationConsumer(serviceInstance: TService, streamName: string, groupName: string): Promise<void>;
/**
* Clean up notification consumers for this instance.
* Stops fallback poller FIRST to prevent race conditions during shutdown.
*/
cleanup(serviceInstance: TService): Promise<void>;
/**
* Get consumer key from stream and group names.
*/
private getConsumerKey;
}
/**
* Get configuration values for notification settings.
*/
export declare function getFallbackInterval(config: any): number;
export declare function getNotificationTimeout(config: any): number;