Created
November 21, 2019 16:12
-
-
Save dgem/ccad562f24a81c5d58bc3d799f86e1e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
logger.info(`enableGracefulShutdown ${config.enableGracefulShutdown}`); | |
// Setup use of the `@godaddy/terminus` module for graceful shutdown | |
if (config.enableGracefulShutdown) { | |
let shuttingDown = false; | |
// const shutdownLogger = newStyleLogger.child({ | |
// component: 'graceful-shutdown' | |
// }); | |
const check = () => { | |
logger.info(`healthCheck ${shuttingDown ? 'down' : 'up'}`); | |
shuttingDown ? Promise.reject('shutting down') : Promise.resolve('up'); | |
}; | |
const onSignal = () => { | |
logger.info(`delay shutdown by ${config.gracefulShutdownDelay}`); | |
shuttingDown = true; | |
}; | |
const beforeShutdown = () => { | |
logger.info('beforeShutdown invoked'); | |
// shutdownLogger.info('shutting down'); | |
}; | |
const errorLogger = message => { | |
logger.info(`error ${message}`); | |
// shutdownLogger.error(message); | |
}; | |
const onShutdown = () => { | |
logger.info('onShutdown'); | |
return new Promise(resolve => { | |
setTimeout(resolve, config.gracefulShutdownDelay); | |
}); | |
// shutdownLogger.info('shutdown complete'); | |
}; | |
const terminusOptions = { | |
healthChecks: { | |
'/health': check | |
}, | |
logger: errorLogger, | |
timeout: config.gracefulShutdownTimeout, | |
signals: ['SIGTERM', 'SIGINT'], | |
onSignal, | |
onShutdown, | |
beforeShutdown | |
}; | |
createTerminus(httpServer, terminusOptions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment