cleanup the shutdown code a bit

This commit is contained in:
Henry Oswald
2020-04-23 11:32:33 +01:00
parent 3513748f73
commit 557dc47e30
2 changed files with 10 additions and 11 deletions

19
app.js
View File

@@ -207,17 +207,16 @@ const resCacher = {
setContentType: 'application/json'
}
const startupTime = Date.now()
let shutdownTime
if (Settings.processLifespanLimitMs) {
Settings.processLifespanLimitMs +=
Settings.processLifespanLimitMs * (Math.random() / 10)
shutdownTime = Date.now() + Settings.processLifespanLimitMs
logger.info('Lifespan limited to ', shutdownTime)
}
const checkIfProcessIsTooOld = function(cont) {
if (typeof Settings.processLifespanLimitMs === 'string') {
Settings.processLifespanLimitMs = parseInt(Settings.processLifespanLimitMs)
Settings.processLifespanLimitMs +=
Settings.processLifespanLimitMs * (Math.random() / 10)
}
if (
Settings.processLifespanLimitMs &&
startupTime + Settings.processLifespanLimitMs < Date.now()
) {
if (shutdownTime && shutdownTime < Date.now()) {
logger.log('shutting down, process is too old')
resCacher.send = function() {}
resCacher.code = 500