mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
add shutdownDrainTimeWindow, drains all connections within time range
This commit is contained in:
parent
49c7bde799
commit
00cca29d9e
4 changed files with 28 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = []
|
||||
|
|
Loading…
Reference in a new issue