import { Worker } from 'cluster';
/**
 * Configuration options for ClusterManager
 *
 * @see {@link https://nodejs.org/docs/latest/api/cluster.html#clustersettings Node.js Cluster Settings}
 */
export interface ClusterManagerOptions {
    cluster?: Cluster;
    /**
     * Serialization method for inter-process communication
     *
     * - `'json'`: Uses JSON serialization (default, compatible with all Node.js versions)
     * - `'advanced'`: Uses advanced serialization (better performance, requires Node.js 16.0.0+)
     *
     * @see {@link https://nodejs.org/docs/latest/api/cluster.html#clustersettings Node.js Cluster Settings}
     */
    serialization?: 'json' | 'advanced';
    /** Function to execute in the primary process during start */
    primaryFn?: () => void | Promise<void>;
    /** Function to execute in the primary process after all workers have been shutdown and just before primary process shutdown */
    primaryShutdownFn?: (signal?: string) => Promise<void>;
    /** Function to execute in worker processes during start */
    workerFn?: () => void | Promise<void>;
    /** Function to execute in worker processes just before worker process shutdown */
    workerShutdownFn?: (signal?: string) => Promise<void>;
    /** Frequency of worker health checks in milliseconds (default: 10000) */
    pingFrequency?: number;
    /** Timeout for worker ping responses in milliseconds (default: 30000) */
    pingTimeout?: number;
    /** Callback to determine action when a stuck worker is killed, if true a new worker will be spawned, if false cluster will shutdown (default: true) */
    stuckWorkerRespawnFunc?: (worker: Worker) => boolean;
    /** Maximum number of times to restart a worker after it has exited unexpectedly (default: 3) */
    restartMaxTimes?: number;
    /** Signals that trigger shutdown (default: ['SIGINT', 'SIGTERM']) */
    shutdownSignals?: NodeJS.Signals[];
    /** Timeout for graceful worker shutdown in milliseconds (default: 30000) */
    shutdownTimeout?: number;
    /** Number of worker processes to spawn (default: number of CPU cores) */
    numWorkers?: number;
}
/**
 * Cluster interface for managing worker processes
 *
 * @see {@link https://nodejs.org/docs/latest/api/cluster.html Node.js Cluster Module}
 */
export interface Cluster {
    worker?: Worker | undefined;
    readonly isPrimary: boolean;
    fork(env?: any): Worker;
    on(event: string, listener: (...args: any[]) => void): Cluster;
    on(event: 'exit', listener: (worker: Worker, code: number, signal: string) => void): this;
    on(event: 'online', listener: (worker: Worker) => void): this;
    /**
     * Configure the primary process settings
     *
     * @param options - Configuration options for the primary process
     * @param options.serialization - Serialization method for IPC messages
     *
     * @see {@link https://nodejs.org/docs/latest/api/cluster.html#clustersetupprimaryoptions Node.js cluster.setupPrimary()}
     */
    setupPrimary(options: {
        serialization: 'json' | 'advanced';
    }): void;
}
/**
 * Internal worker state tracking
 */
export interface WorkerState {
    id: number;
    worker: Worker;
    restartCount: number;
    lastPing: number;
    pendingPing: boolean;
    isShuttingDown: boolean;
}
/**
 * Events emitted by ClusterManager
 */
export interface ClusterManagerEvents {
    'worker:started': (worker: Worker) => void;
    'worker:died': (worker: Worker, code: number | null, signal: string | null) => void;
    'worker:stuck': (worker: Worker) => void;
    'worker:restarted': (worker: Worker, restartCount: number) => void;
    'worker:restart-limit-exceeded': (worker: Worker, restartCount: number) => void;
    'shutdown:started': (signal?: string) => void;
    'shutdown:completed': () => void;
    error: (error: Error) => void;
}
/**
 * Message types for inter-process communication
 */
export interface PingMessage {
    type: 'ping';
    timestamp: number;
}
export interface PongMessage {
    type: 'pong';
    timestamp: number;
}
export interface ShutdownMessage {
    type: 'shutdown';
    signal?: string;
}
export type IPCMessage = PingMessage | PongMessage | ShutdownMessage;
//# sourceMappingURL=types.d.ts.map