add variance into shutdown time to avoid stampeed
This commit is contained in:
committed by
Henry Oswald
parent
b445f7fb78
commit
3513748f73
25
app.js
25
app.js
@@ -208,27 +208,34 @@ const resCacher = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const startupTime = Date.now()
|
const startupTime = Date.now()
|
||||||
const checkIfProcessIsTooOld = function() {
|
const checkIfProcessIsTooOld = function(cont) {
|
||||||
|
if (typeof Settings.processLifespanLimitMs === 'string') {
|
||||||
|
Settings.processLifespanLimitMs = parseInt(Settings.processLifespanLimitMs)
|
||||||
|
Settings.processLifespanLimitMs +=
|
||||||
|
Settings.processLifespanLimitMs * (Math.random() / 10)
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
Settings.processLifespanLimitMs &&
|
Settings.processLifespanLimitMs &&
|
||||||
startupTime + Settings.processLifespanLimitMs < Date.now()
|
startupTime + Settings.processLifespanLimitMs < Date.now()
|
||||||
) {
|
) {
|
||||||
logger.log('shutting down, process is too old')
|
logger.log('shutting down, process is too old')
|
||||||
resCacher.send = function() {}
|
resCacher.send = function() {}
|
||||||
resCacher.statusCode = 500
|
resCacher.code = 500
|
||||||
resCacher.body = { processToOld: true }
|
resCacher.body = { processToOld: true }
|
||||||
|
} else {
|
||||||
|
cont()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.smokeTest) {
|
if (Settings.smokeTest) {
|
||||||
const runSmokeTest = function() {
|
const runSmokeTest = function() {
|
||||||
checkIfProcessIsTooOld()
|
checkIfProcessIsTooOld(function() {
|
||||||
logger.log('running smoke tests')
|
logger.log('running smoke tests')
|
||||||
smokeTest.run(require.resolve(__dirname + '/test/smoke/js/SmokeTests.js'))(
|
smokeTest.run(
|
||||||
{},
|
require.resolve(__dirname + '/test/smoke/js/SmokeTests.js')
|
||||||
resCacher
|
)({}, resCacher)
|
||||||
)
|
return setTimeout(runSmokeTest, 30 * 1000)
|
||||||
return setTimeout(runSmokeTest, 30 * 1000)
|
})
|
||||||
}
|
}
|
||||||
runSmokeTest()
|
runSmokeTest()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user