@totalsoft/graceful-shutdown
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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
}

Readme

Keywords

Package Sidebar

Install

npm i @totalsoft/graceful-shutdown

Weekly Downloads

242

Version

1.1.0

License

MIT

Unpacked Size

36.3 kB

Total Files

15

Last publish

Collaborators

  • osstotalsoft