From 917ce27a2c51cd05d19ad9c96cc2ed14bc98a8fe Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 20 Nov 2014 12:50:19 +0000 Subject: [PATCH] add a double message check --- libraries/redis-wrapper/index.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/redis-wrapper/index.coffee b/libraries/redis-wrapper/index.coffee index 386765af38..770a5030d0 100644 --- a/libraries/redis-wrapper/index.coffee +++ b/libraries/redis-wrapper/index.coffee @@ -26,6 +26,7 @@ module.exports = RedisSharelatex = pub = RedisSharelatex.createClient(connectionInfo) redisIsOk = true + lastPingMessage = "" heartbeatInterval = 2000 #ms isAliveTimeout = 10000 #ms @@ -37,11 +38,15 @@ module.exports = RedisSharelatex = if error? console.error "ERROR: failed to subscribe to #{heartbeatChannel} channel", error sub.on "message", (channel, message) -> + if lastPingMessage == message #we got the same message twice + redisIsOk = false + lastPingMessage = message if channel == heartbeatChannel lastHeartbeat = Date.now() setInterval -> - pub.publish heartbeatChannel, "PING" + message = "ping:#{Date.now()}" + pub.publish heartbeatChannel, message , heartbeatInterval isAlive = ->