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 = ->
logger.log {delay_ms:Settings.forceDrainMsDelay}, "starting force drain after timeout"
setTimeout ()->
logger.log "starting drain"
DrainManager.startDrain(io, 4)
logger.log "starting drain over #{Settings.shutdownDrainTimeWindow} mins"
DrainManager.startDrainTimeWindow(io, Settings.shutdownDrainTimeWindow)
, Settings.forceDrainMsDelay
shutDownInProgress = false

View file

@ -1,6 +1,11 @@
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) ->
# Clear out any old interval
clearInterval @interval

View file

@ -50,6 +50,8 @@ settings =
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
checkEventOrder: process.env['CHECK_EVENT_ORDER'] or false

View file

@ -12,6 +12,24 @@ describe "DrainManager", ->
sockets:
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", ->
beforeEach ->
@clients = []