mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
incremented version and added basic health check function in
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user