Use new robust subscription model

This commit is contained in:
James Allen 2014-11-19 11:09:42 +00:00
parent 5ec9e587f0
commit d6532c63f8
4 changed files with 12 additions and 5 deletions

View file

@ -1,7 +1,7 @@
Settings = require 'settings-sharelatex'
redis = require("redis-sharelatex")
rclientPub = redis.createClient(Settings.redis.web)
rclientSub = redis.createClient(Settings.redis.web)
rclientSub = redis.createRobustSubscriptionClient(Settings.redis.web)
module.exports = EditorRealTimeController =
rclientPub: rclientPub
@ -18,7 +18,9 @@ module.exports = EditorRealTimeController =
listenForEditorEvents: () ->
@rclientSub.subscribe "editor-events"
@rclientSub.on "message", @_processEditorEvent.bind(@)
@rclientSub.on "message", (channel, message) ->
return unless channel == "editor-events"
EditorRealTimeController._processEditorEvent(channel, message)
_processEditorEvent: (channel, message) ->
io = require('../../infrastructure/Server').io

View file

@ -2,10 +2,11 @@ logger = require "logger-sharelatex"
metrics = require('../../infrastructure/Metrics')
Settings = require 'settings-sharelatex'
redis = require("redis-sharelatex")
rclient = redis.createClient(Settings.redis.web)
DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
EditorRealTimeController = require("./EditorRealTimeController")
rclient = redis.createRobustSubscriptionClient(Settings.redis.web)
module.exports = EditorUpdatesController =
_applyUpdate: (client, project_id, doc_id, update, callback = (error) ->) ->
metrics.inc "editor.doc-update", 0.3
@ -30,7 +31,9 @@ module.exports = EditorUpdatesController =
listenForUpdatesFromDocumentUpdater: () ->
rclient.subscribe "applied-ops"
rclient.on "message", @_processMessageFromDocumentUpdater.bind(@)
rclient.on "message", (channel, message) ->
return unless channel == "applied-ops"
EditorUpdatesController._processMessageFromDocumentUpdater(channel, message)
_processMessageFromDocumentUpdater: (channel, message) ->
message = JSON.parse message

View file

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

View file

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