UNPKG

@rudderstack/integrations-lib

Version:

A comprehensive TypeScript library providing shared utilities, SDKs, and tools for RudderStack integrations and destinations.

149 lines 4.03 kB
import { EventEmitter } from 'events'; import { ClusterManagerOptions, ClusterManagerEvents } from './types'; /** * ClusterManager - A cluster lifecycle management system * * The manager supports the following features: * - Graceful shutdown with configurable timeout * - Worker health monitoring with ping/pong mechanism * - Automatic worker restart with configurable limits * - Signal handling for shutdown triggers * - Flexible primary and worker function handlers */ export declare class ClusterManager extends EventEmitter { private readonly options; private readonly workers; private started; private isShuttingDown; private shutdownPromise; private healthCheckInterval; private signalHandlers; constructor(options?: ClusterManagerOptions); /** * Initialize the cluster manager with primary process configuration * * @see {@link https://nodejs.org/docs/latest/api/cluster.html#clustersetupprimaryoptions Node.js cluster.setupPrimary()} */ private initialize; /** * Starts the cluster manager * In primary process: starts workers and health monitoring * In worker process: executes worker function */ start(): Promise<void>; /** * Initiates graceful shutdown of the cluster */ shutdown(signal?: string): Promise<void>; /** * Sets up signal handlers for graceful shutdown */ private setupSignalHandlers; /** * Removes signal handlers */ private removeSignalHandlers; /** * Starts the primary process */ private startPrimary; /** * Starts a worker process */ private startWorker; /** * Sets up cluster event handlers for the primary process */ private setupClusterEventHandlers; /** * Sets up IPC message handlers for worker processes */ private setupWorkerMessageHandlers; /** * Spawns a new worker and sets up its state */ private spawnWorker; /** * Handles messages from workers */ private handleWorkerMessage; /** * Handles ping messages in worker processes */ private handleWorkerPing; /** * Starts health monitoring for all workers */ private startHealthMonitoring; /** * Stops health monitoring */ private stopHealthMonitoring; /** * Performs health check on all workers */ private performHealthCheck; /** * Sends a ping message to a worker */ private sendPingToWorker; /** * Handles a stuck worker */ private handleStuckWorker; /** * Handles worker exit events */ private handleWorkerExit; private getWorkerId; private getCurrentWorkerId; /** * Handles unexpected worker exits with restart logic */ private handleUnexpectedWorkerExit; /** * Shuts down the primary process */ private shutdownPrimary; /** * Shuts down all workers gracefully */ private shutdownAllWorkers; /** * Waits for all workers to exit */ private waitForAllWorkersToExit; /** * Force kills all remaining workers */ private forceKillAllWorkers; /** * Shuts down a worker process */ private shutdownWorker; /** * Gets the current number of active workers */ getWorkerCount(): number; /** * Gets information about all workers */ getWorkerInfo(): Array<{ id: number; pid: number; restartCount: number; }>; /** * Checks if the cluster is currently started */ isStarted(): boolean; /** * Checks if the cluster is currently shutting down */ isShutdown(): boolean; } export interface ClusterManagerEmitter { on<K extends keyof ClusterManagerEvents>(event: K, listener: ClusterManagerEvents[K]): this; emit<K extends keyof ClusterManagerEvents>(event: K, ...args: Parameters<ClusterManagerEvents[K]>): boolean; } //# sourceMappingURL=manager.d.ts.map