import { Server } from "http"; import { RealtimeProvider } from "@rebasepro/types"; interface ShutdownConfig { server: Server; cronScheduler?: { stop(): void; }; realtimeServices: Record; } /** * Minimal structural view of the backend instance needed by * {@link installShutdownHandlers}. Structural (rather than importing * `RebaseBackendInstance`) to avoid a circular import with `../init`. */ interface ShutdownCapableBackend { shutdown(timeoutMs?: number): Promise; } export interface ShutdownHandlerOptions { /** * Cleanup to run after the backend has drained — e.g. closing your * database pool: `onCleanup: () => pool.end()`. */ onCleanup?: () => Promise | void; /** * Hard force-exit timeout in milliseconds. If the shutdown sequence * (drain + cleanup) has not completed by then, the process exits with * code 1. Also passed to `backend.shutdown()` as its drain timeout. * * @default 15000 */ timeoutMs?: number; /** * Process signals to handle. * @default ["SIGTERM", "SIGINT"] */ signals?: NodeJS.Signals[]; /** @internal Injectable exit function for tests. */ exit?: (code: number) => void; } /** * Install graceful-shutdown signal handlers for a Rebase backend. * * On the first signal received, this drains the backend via * `backend.shutdown()` — which stops the cron scheduler, tears down * realtime services, and closes the HTTP server. Do **not** call * `server.close()` yourself in addition: closing an already-closing * server deadlocks, because the second close's callback never fires. * * After the drain, `onCleanup` runs (close your database pool here), * and the process exits 0. A force-exit timer guards the whole * sequence: if it has not completed within `timeoutMs`, the process * exits 1. Repeated signals while a shutdown is in flight are ignored. * * @returns An uninstall function that removes the signal listeners * (useful in tests). * * @example * ```ts * const backend = await initializeRebaseBackend({ ... }); * installShutdownHandlers(backend, { onCleanup: () => pool.end() }); * ``` */ export declare function installShutdownHandlers(backend: ShutdownCapableBackend, options?: ShutdownHandlerOptions): () => void; export declare function createShutdown(config: ShutdownConfig): (timeoutMs?: number) => Promise; export {};