mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add a close() method to terminate the module cleanly
closes the statsd connection and cancels registered interval timers prevents express from hanging when trying to shutdown
This commit is contained in:
parent
60857982b6
commit
30070f23b8
2 changed files with 13 additions and 1 deletions
|
@ -6,10 +6,15 @@ hostname = require('os').hostname()
|
||||||
|
|
||||||
buildKey = (key)-> "#{name}.#{hostname}.#{key}"
|
buildKey = (key)-> "#{name}.#{hostname}.#{key}"
|
||||||
|
|
||||||
|
destructors = []
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
initialize: (_name) ->
|
initialize: (_name) ->
|
||||||
name = _name
|
name = _name
|
||||||
|
|
||||||
|
registerDestructor: (func) ->
|
||||||
|
destructors.push func
|
||||||
|
|
||||||
set : (key, value, sampleRate = 1)->
|
set : (key, value, sampleRate = 1)->
|
||||||
statsd.set buildKey(key), value, sampleRate
|
statsd.set buildKey(key), value, sampleRate
|
||||||
|
|
||||||
|
@ -35,3 +40,7 @@ module.exports =
|
||||||
http: require "./http"
|
http: require "./http"
|
||||||
open_sockets: require "./open_sockets"
|
open_sockets: require "./open_sockets"
|
||||||
|
|
||||||
|
close: () ->
|
||||||
|
for func in destructors
|
||||||
|
func()
|
||||||
|
statsd.close()
|
||||||
|
|
|
@ -3,9 +3,12 @@ seconds = 1000
|
||||||
|
|
||||||
module.exports = OpenSocketsMonitor =
|
module.exports = OpenSocketsMonitor =
|
||||||
monitor: (logger) ->
|
monitor: (logger) ->
|
||||||
setInterval () ->
|
interval = setInterval () ->
|
||||||
OpenSocketsMonitor.gaugeOpenSockets()
|
OpenSocketsMonitor.gaugeOpenSockets()
|
||||||
, 5 * seconds
|
, 5 * seconds
|
||||||
|
Metrics = require "./metrics"
|
||||||
|
Metrics.registerDestructor () ->
|
||||||
|
clearInterval(interval)
|
||||||
|
|
||||||
gaugeOpenSockets: () ->
|
gaugeOpenSockets: () ->
|
||||||
Metrics = require "./metrics"
|
Metrics = require "./metrics"
|
||||||
|
|
Loading…
Reference in a new issue