2.0.0 • Published 2 months ago
@totalsoft/graceful-shutdown v2.0.0
graceful-shutdown
Graceful shutdown after intercepting signals and unhandled exceptions.
Installation
npm i @totalsoft/graceful-shutdown
or
yarn add @totalsoft/graceful-shutdown
Usage
const { gracefulShutdown } = require('@totalsoft/graceful-shutdown')
async function cleanup() {
// Perform cleanup before shutdown
}
gracefulShutdown({
onShutdown: cleanup,
terminationSignals: ["SIGINT", "SIGTERM", "SIGUSR1", "SIGUSR2"],
unrecoverableEvents: ["uncaughtException", "unhandledRejection"],
logger: console,
timeout: 5000
})
Options
export interface GracefulShutdownOptions {
// Set an async handler to be called at shutdown
onShutdown?: (_: any) => Promise<void>
// Set a timeout in milliseconds to wait for graceful shutdown.
timeout?: number
// A list of signals that trigger shutdown (eg. SIGINT, SIGTERM).
terminationSignals?: string[]
// A list of process events that trigger shutdown (eg. `unrecoverableException`)
unrecoverableEvents?: string[]
// A logger for shutdown events
logger?: Logger
}