@digicat/termination-manager
The one true way of terminating services.
Termination tasks can be added with different priorities. Tasks are executed in
descending priority order. Tasks with the same priority are terminated
concurrently.
Takes callback functions which application code can use to log messages.
Supports configurable grace periods to ensure the process does terminate.
Handles SIGINT
and SIGTERM
signals and listens for uncaught exceptions and
unhandled rejections. When these signals are received, the process is terminated
gracefully. Uncaught exceptions and unhandled rejections cause the process to be
terminated with a 0 millisecond grace period.
Requires Node.js 8.6 or later.
Usage
const TerminationManager = require('@digicat/termination-manager')
const manager = new TerminationManager({
grace: 5000,
drainGrace: 5000,
onDrainTimeout () {},
onSigint () {},
onSigterm () {},
onStopError (err) {},
onUncaughtException (err) {},
onUnhandledRejection () {}
})
manager.add({
name: 'db'
priority: 0,
async stop (grace) {
}
})
manager.crash()
manager.exit({code = 0, grace = 5000})