1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-04-04 12:06:49 +00:00

Merge branch 'redis-queue'

This commit is contained in:
James Allen 2014-08-11 12:10:25 +01:00
commit b7ed3bab8f
2 changed files with 16 additions and 28 deletions
services/web
app/coffee/Features/DocumentUpdater
test/UnitTests/coffee/DocumentUpdater

View file

@ -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)

View file

@ -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 ->