Add in http health check end points for redis subscription channels

This commit is contained in:
James Allen 2014-11-19 14:12:37 +00:00
parent 34e20e99f5
commit 8b9a26d6f3
5 changed files with 23 additions and 4 deletions

View file

@ -1,11 +1,14 @@
Settings = require 'settings-sharelatex'
redis = require("redis-sharelatex")
rclientPub = redis.createClient(Settings.redis.web)
rclientSub = redis.createRobustSubscriptionClient(Settings.redis.web)
rclientSub = redis.createMonitoredSubscriptionClient(Settings.redis.web)
module.exports = EditorRealTimeController =
rclientPub: rclientPub
rclientSub: rclientSub
isRedisPubSubAlive: () ->
rclientSub.isAlive()
emitToRoom: (room_id, message, payload...) ->
@rclientPub.publish "editor-events", JSON.stringify

View file

@ -5,7 +5,7 @@ redis = require("redis-sharelatex")
DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
EditorRealTimeController = require("./EditorRealTimeController")
rclient = redis.createRobustSubscriptionClient(Settings.redis.web)
rclient = redis.createMonitoredSubscriptionClient(Settings.redis.web)
module.exports = EditorUpdatesController =
_applyUpdate: (client, project_id, doc_id, update, callback = (error) ->) ->
@ -29,6 +29,9 @@ module.exports = EditorUpdatesController =
update.meta.user_id = user_id
EditorUpdatesController._applyUpdate client, project_id, doc_id, update
isRedisPubSubAlive: () ->
rclient.isAlive()
listenForUpdatesFromDocumentUpdater: () ->
rclient.subscribe "applied-ops"
rclient.on "message", (channel, message) ->

View file

@ -8,6 +8,7 @@ AuthorizationManager = require('./Features/Security/AuthorizationManager')
EditorController = require("./Features/Editor/EditorController")
EditorRouter = require("./Features/Editor/EditorRouter")
EditorUpdatesController = require("./Features/Editor/EditorUpdatesController")
EditorRealTimeController = require("./Features/Editor/EditorRealTimeController")
Settings = require('settings-sharelatex')
TpdsController = require('./Features/ThirdPartyDataStore/TpdsController')
SubscriptionRouter = require './Features/Subscription/SubscriptionRouter'
@ -175,6 +176,18 @@ module.exports = class Router
req.session.destroy()
app.get '/health_check', HealthCheckController.check
app.get '/health_check/redis/doc_updates', (req, res, next) ->
if EditorUpdatesController.isRedisPubSubAlive()
res.send(200)
else
res.send(500)
app.get '/health_check/redis/websockets', (req, res, next) ->
if EditorRealTimeController.isRedisPubSubAlive()
res.send(200)
else
res.send(500)
app.get "/status/compiler/:Project_id", SecurityManager.requestCanAccessProject, (req, res) ->
sendRes = _.once (statusCode, message)->

View file

@ -9,7 +9,7 @@ describe "EditorRealTimeController", ->
"redis-sharelatex":
createClient: () ->
auth:->
createRobustSubscriptionClient: () ->
createMonitoredSubscriptionClient: () ->
auth:->
"../../infrastructure/Server" : io: @io = {}
@EditorRealTimeController.rclientPub = publish: sinon.stub()

View file

@ -18,7 +18,7 @@ describe "EditorUpdatesController", ->
"../../infrastructure/Metrics" : @metrics = { set: sinon.stub(), inc: sinon.stub() }
"../../infrastructure/Server" : io: @io = {}
"redis-sharelatex" :
createRobustSubscriptionClient: ()=>
createMonitoredSubscriptionClient: ()=>
@rclient = {auth:->}
describe "_applyUpdate", ->