From acbfc465dcd3e937c20d7b8ea88e5d32a62071ff Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 9 Apr 2020 14:11:04 +0100 Subject: [PATCH] add variance into shutdown time to avoid stampeed --- services/clsi/app.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/services/clsi/app.js b/services/clsi/app.js index ec67140c1c..f96d019fdf 100644 --- a/services/clsi/app.js +++ b/services/clsi/app.js @@ -208,27 +208,34 @@ const resCacher = { } 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 ( Settings.processLifespanLimitMs && startupTime + Settings.processLifespanLimitMs < Date.now() ) { logger.log('shutting down, process is too old') resCacher.send = function() {} - resCacher.statusCode = 500 + resCacher.code = 500 resCacher.body = { processToOld: true } + } else { + cont() } } if (Settings.smokeTest) { const runSmokeTest = function() { - checkIfProcessIsTooOld() - logger.log('running smoke tests') - smokeTest.run(require.resolve(__dirname + '/test/smoke/js/SmokeTests.js'))( - {}, - resCacher - ) - return setTimeout(runSmokeTest, 30 * 1000) + checkIfProcessIsTooOld(function() { + logger.log('running smoke tests') + smokeTest.run( + require.resolve(__dirname + '/test/smoke/js/SmokeTests.js') + )({}, resCacher) + return setTimeout(runSmokeTest, 30 * 1000) + }) } runSmokeTest() }