diff --git a/lib/utils/sbc-pinger.js b/lib/utils/sbc-pinger.js index 729dcb5c..3b4d6f17 100644 --- a/lib/utils/sbc-pinger.js +++ b/lib/utils/sbc-pinger.js @@ -100,6 +100,39 @@ module.exports = (logger) => { else if (K8S) { lifecycleEmitter.scaleIn = () => process.exit(0); } + else { + process.on('SIGUSR1', () => { + logger.info('received SIGUSR1: begin drying up calls for scale-in'); + dryUpCalls = true; + + const {srf} = require('../..'); + const {writeSystemAlerts} = srf.locals; + if (writeSystemAlerts) { + const {SystemState, FEATURE_SERVER} = require('./constants'); + writeSystemAlerts({ + system_component: FEATURE_SERVER, + state : SystemState.GracefulShutdownInProgress, + fields : { + detail: `feature-server with process_id ${process.pid} shutdown in progress`, + host: srf.locals?.ipv4 + } + }); + } + pingProxies(srf); + + // if we have zero calls, we can complete the scale-in right + setTimeout(() => { + const calls = srf.locals.sessionTracker.count; + if (calls === 0) { + logger.info('scale-in can complete immediately as we have no calls in progress'); + process.exit(0); + } + else { + logger.info(`${calls} calls in progress; scale-in will complete when they are done`); + } + }, 5000); + }); + } async function pingProxies(srf) {