From 0a44aa9e71ab6fc11ee514b488532d09b0d1732f Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 7 Aug 2014 13:19:10 +0100 Subject: [PATCH] Push into doc updater queue rather than pub/sub for updates --- .../DocumentUpdaterHandler.coffee | 12 ++++--- .../DocumentUpdaterHandlerTests.coffee | 32 ++++++------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee b/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee index 3d4d49c827..c5fcc11209 100644 --- a/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee +++ b/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee @@ -18,12 +18,14 @@ module.exports = DocumentUpdaterHandler = queueChange : (project_id, doc_id, change, sl_req_id, callback = ()->)-> {callback, sl_req_id} = slReqIdHelper.getCallbackAndReqId(callback, sl_req_id) jsonChange = JSON.stringify change - rclient.rpush keys.pendingUpdates(doc_id:doc_id), jsonChange, (error)-> + doc_key = keys.combineProjectIdAndDocId(project_id, doc_id) + multi = rclient.multi() + multi.rpush keys.pendingUpdates(doc_id:doc_id), jsonChange + multi.sadd keys.docsWithPendingUpdates, doc_key + multi.rpush "pending-updates-list", doc_key + multi.exec (error) -> return callback(error) if error? - doc_key = keys.combineProjectIdAndDocId(project_id, doc_id) - rclient.sadd keys.docsWithPendingUpdates, doc_key, (error) -> - return callback(error) if error? - rclient.publish "pending-updates", doc_key, callback + callback() flushProjectToMongo: (project_id, sl_req_id, callback = (error) ->)-> {callback, sl_req_id} = slReqIdHelper.getCallbackAndReqId(callback, sl_req_id) diff --git a/services/web/test/UnitTests/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee b/services/web/test/UnitTests/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee index 097269a731..f0bd52f03e 100644 --- a/services/web/test/UnitTests/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee @@ -40,9 +40,10 @@ describe 'Flushing documents :', -> "range":{"start":{"row":2,"column":2},"end":{"row":2,"column":3}}, "text":"e" } - @rclient.rpush = sinon.stub().callsArg(2) - @rclient.publish = sinon.stub().callsArg(2) - @rclient.sadd = sinon.stub().callsArg(2) + @rclient.multi = sinon.stub().returns @rclient + @rclient.exec = sinon.stub().callsArg(0) + @rclient.rpush = sinon.stub() + @rclient.sadd = sinon.stub() @callback = sinon.stub() describe "successfully", -> @@ -54,9 +55,9 @@ describe 'Flushing documents :', -> .calledWith("PendingUpdates:#{@doc_id}", JSON.stringify(@change)) .should.equal true - it "should notify the doc updater of the change via pub/sub", -> - @rclient.publish - .calledWith("pending-updates", "#{@project_id}:#{@doc_id}") + it "should notify the doc updater of the change via the pending-updates-list queue", -> + @rclient.rpush + .calledWith("pending-updates-list", "#{@project_id}:#{@doc_id}") .should.equal true it "should push the doc id into the pending updates set", -> @@ -64,29 +65,14 @@ describe 'Flushing documents :', -> .calledWith("DocsWithPendingUpdates", "#{@project_id}:#{@doc_id}") .should.equal true - describe "with error connecting to redis during push", -> + describe "with error connecting to redis during exec", -> beforeEach -> - @rclient.rpush = sinon.stub().callsArgWith(2, new Error("something went wrong")) + @rclient.exec = sinon.stub().callsArgWith(0, new Error("something went wrong")) @handler.queueChange(@project_id, @doc_id, @change, @callback) it "should return an error", -> @callback.calledWithExactly(sinon.match(Error)).should.equal true - describe "with error connecting to redis during publish", -> - beforeEach -> - @rclient.publish = sinon.stub().callsArgWith(2, new Error("something went wrong")) - @handler.queueChange(@project_id, @doc_id, @change, @callback) - - it "should return an error", -> - @callback.calledWithExactly(sinon.match(Error)).should.equal true - - describe "with error connecting to redis during sadd", -> - beforeEach -> - @rclient.sadd = sinon.stub().callsArgWith(2, new Error("something went wrong")) - @handler.queueChange(@project_id, @doc_id, @change, @callback) - - it "should return an error", -> - @callback.calledWithExactly(sinon.match(Error)).should.equal true describe 'flushProjectToMongo', -> beforeEach ->