import { OnModuleInit, OnModuleDestroy } from '@nestjs/common'; import type Redis from 'ioredis'; /** * Lock heartbeat service * * Provides heartbeat mechanism for distributed lock instances. * Each instance sends periodic heartbeats to Redis to indicate it's alive. * Dead instances can be detected by checking if their heartbeat has expired. * * @example * ```typescript * constructor(private heartbeatService: LockHeartbeatService) {} * * async isInstanceAlive(instanceId: string): Promise { * return this.heartbeatService.isInstanceAlive(instanceId); * } * ``` */ export declare class LockHeartbeatService implements OnModuleInit, OnModuleDestroy { private readonly logger; private readonly instanceId; private redis; private heartbeatTimer; /** * Heartbeat interval in milliseconds * @default 5000 (5 seconds) - reduced for faster failure detection */ private readonly heartbeatInterval; /** * Heartbeat TTL in seconds (3x interval for safety) * @default 15 (15 seconds) - adjusted to match new interval */ private readonly heartbeatTtl; constructor(instanceId?: string); onModuleInit(): Promise; onModuleDestroy(): Promise; /** * Set Redis client (required for dependency injection) */ setRedisClient(redis: Redis): void; /** * Send heartbeat to Redis * Stores instance information with TTL */ private sendHeartbeat; /** * Remove heartbeat record from Redis */ private removeHeartbeat; /** * Check if an instance is alive by checking its heartbeat * * @param instanceId - Instance identifier to check * @returns True if instance is alive (heartbeat exists), false otherwise */ isInstanceAlive(instanceId: string): Promise; /** * Get heartbeat information for an instance * * @param instanceId - Instance identifier * @returns Heartbeat data or null if not found */ getHeartbeatInfo(instanceId: string): Promise<{ instanceId: string; timestamp: number; pid: number; } | null>; /** * Get all active instances (with heartbeat) * * **Note**: Uses SCAN command to avoid blocking Redis in production. * * @returns Array of instance IDs that are currently alive */ getActiveInstances(): Promise; /** * Get current instance ID */ getInstanceId(): string; private createInstanceId; }