add shutdownDrainTimeWindow, drains all connections within time range

This commit is contained in:
Henry Oswald 2019-08-13 11:12:04 +01:00
parent 49c7bde799
commit 00cca29d9e
4 changed files with 28 additions and 3 deletions

View file

@ -113,8 +113,8 @@ shutdownCleanly = (signal) ->
forceDrain = -> forceDrain = ->
logger.log {delay_ms:Settings.forceDrainMsDelay}, "starting force drain after timeout" logger.log {delay_ms:Settings.forceDrainMsDelay}, "starting force drain after timeout"
setTimeout ()-> setTimeout ()->
logger.log "starting drain" logger.log "starting drain over #{Settings.shutdownDrainTimeWindow} mins"
DrainManager.startDrain(io, 4) DrainManager.startDrainTimeWindow(io, Settings.shutdownDrainTimeWindow)
, Settings.forceDrainMsDelay , Settings.forceDrainMsDelay
shutDownInProgress = false shutDownInProgress = false

View file

@ -1,6 +1,11 @@
logger = require "logger-sharelatex" logger = require "logger-sharelatex"
module.exports = module.exports = DrainManager =
startDrainTimeWindow: (io, minsToDrain)->
drainPerMin = io.sockets.clients().length / minsToDrain
DrainManager.startDrain(io, drainPerMin / 60)
startDrain: (io, rate) -> startDrain: (io, rate) ->
# Clear out any old interval # Clear out any old interval
clearInterval @interval clearInterval @interval

View file

@ -50,6 +50,8 @@ settings =
forceDrainMsDelay: process.env['FORCE_DRAIN_MS_DELAY'] or false forceDrainMsDelay: process.env['FORCE_DRAIN_MS_DELAY'] or false
shutdownDrainTimeWindow: process.env['SHUTDOWN_DRAIN_TIME_WINDOW'] or 9
continualPubsubTraffic: process.env['CONTINUAL_PUBSUB_TRAFFIC'] or false continualPubsubTraffic: process.env['CONTINUAL_PUBSUB_TRAFFIC'] or false
checkEventOrder: process.env['CHECK_EVENT_ORDER'] or false checkEventOrder: process.env['CHECK_EVENT_ORDER'] or false

View file

@ -12,6 +12,24 @@ describe "DrainManager", ->
sockets: sockets:
clients: sinon.stub() clients: sinon.stub()
describe "startDrainTimeWindow", ->
beforeEach ->
@clients = []
for i in [0..1619]
@clients[i] = {
id: i
emit: sinon.stub()
}
@io.sockets.clients.returns @clients
@DrainManager.startDrain = sinon.stub()
it "should set a drain rate fast enough", (done)->
@DrainManager.startDrainTimeWindow(@io, 9)
console.log(@DrainManager.startDrain.args[0])
@DrainManager.startDrain.calledWith(@io, 3).should.equal true
done()
describe "reconnectNClients", -> describe "reconnectNClients", ->
beforeEach -> beforeEach ->
@clients = [] @clients = []