mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 04:13:41 -05:00
incremented version and added basic health check function in
This commit is contained in:
parent
6da4f3eef5
commit
e133c7101e
2 changed files with 37 additions and 2 deletions
|
@ -18,4 +18,39 @@ module.exports = RedisSharelatex =
|
|||
delete standardOpts.port
|
||||
delete standardOpts.host
|
||||
client = require("redis").createClient opts.port, opts.host, standardOpts
|
||||
return client
|
||||
return client
|
||||
|
||||
|
||||
activeHealthCheckRedis: (connectionInfo)->
|
||||
sub = RedisSharelatex.createClient(connectionInfo)
|
||||
pub = RedisSharelatex.createClient(connectionInfo)
|
||||
|
||||
heartbeatInterval = 2000 #ms
|
||||
isAliveTimeout = 10000 #ms
|
||||
|
||||
id = require("crypto").pseudoRandomBytes(16).toString("hex")
|
||||
heartbeatChannel = "heartbeat-#{id}"
|
||||
lastHeartbeat = Date.now()
|
||||
|
||||
sub.subscribe heartbeatChannel, (error) ->
|
||||
if error?
|
||||
console.error "ERROR: failed to subscribe to #{heartbeatChannel} channel", error
|
||||
sub.on "message", (channel, message) ->
|
||||
if channel == heartbeatChannel
|
||||
lastHeartbeat = Date.now()
|
||||
|
||||
setInterval ->
|
||||
pub.publish heartbeatChannel, "PING"
|
||||
, heartbeatInterval
|
||||
|
||||
isAlive = ->
|
||||
timeSinceLastHeartbeat = Date.now() - lastHeartbeat
|
||||
if timeSinceLastHeartbeat > isAliveTimeout
|
||||
console.error "heartbeat from redis timed out"
|
||||
return false
|
||||
else
|
||||
return true
|
||||
|
||||
return {
|
||||
isAlive:isAlive
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "redis-sharelatex",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.7",
|
||||
"description": "redis wrapper for node which will either use sentinal or normal redis",
|
||||
"main": "index.js",
|
||||
"author": "henry oswald @ sharelatex",
|
||||
|
|
Loading…
Reference in a new issue