fastify-graceful-shutdown
Advanced tools
Comparing version 3.5.2 to 3.5.3
18
index.js
@@ -10,3 +10,5 @@ 'use strict' | ||
function fastifyGracefulShutdown(fastify, opts, next) { | ||
const logger = fastify.log.child({ plugin: 'fastify-graceful-shutdown' }) | ||
const logger = fastify.log | ||
? fastify.log.child({ plugin: 'fastify-graceful-shutdown' }) | ||
: undefined | ||
const handlers = [] | ||
@@ -39,10 +41,10 @@ const timeout = opts.timeout || 10000 | ||
if (err) { | ||
logger.error({ err: err, signal: signal }, 'process terminated') | ||
logger.error?.({ err: err, signal: signal }, 'process terminated') | ||
// Avoid losing data | ||
logger.flush() | ||
logger.flush?.() | ||
handlerEventListener.exit(1) | ||
} else { | ||
logger.debug({ signal: signal }, 'process terminated') | ||
logger.debug?.({ signal: signal }, 'process terminated') | ||
// Avoid losing data | ||
logger.flush() | ||
logger.flush?.() | ||
handlerEventListener.exit(0) | ||
@@ -54,3 +56,3 @@ } | ||
setTimeout(() => { | ||
logger.error( | ||
logger.error?.( | ||
{ signal: signal, timeout: timeout }, | ||
@@ -78,3 +80,3 @@ 'terminate process after timeout', | ||
addHandler((signal, cb) => { | ||
logger.debug({ signal: signal }, 'triggering close hook') | ||
logger.debug?.({ signal: signal }, 'triggering close hook') | ||
fastify.close(cb) | ||
@@ -87,3 +89,3 @@ }) | ||
terminateAfterTimeout(signal, timeout) | ||
logger.debug({ signal: signal }, 'received signal') | ||
logger.debug?.({ signal: signal }, 'received signal') | ||
shutdown(signal) | ||
@@ -90,0 +92,0 @@ } |
{ | ||
"name": "fastify-graceful-shutdown", | ||
"version": "3.5.2", | ||
"version": "3.5.3", | ||
"description": "Gracefully shutdown fastify", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
7318
108