mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
Merge pull request #505 from sharelatex/ja-redis-cluster-refactor
Allow writing of clsi cookie cache to redis cluster secondary
This commit is contained in:
commit
9d2bdcf8da
2 changed files with 29 additions and 5 deletions
|
@ -2,6 +2,8 @@ Settings = require "settings-sharelatex"
|
||||||
request = require('request')
|
request = require('request')
|
||||||
RedisWrapper = require("../../infrastructure/RedisWrapper")
|
RedisWrapper = require("../../infrastructure/RedisWrapper")
|
||||||
rclient = RedisWrapper.client("clsi_cookie")
|
rclient = RedisWrapper.client("clsi_cookie")
|
||||||
|
if Settings.redis.clsi_cookie_secondary?
|
||||||
|
rclient_secondary = RedisWrapper.client("clsi_cookie_secondary")
|
||||||
Cookie = require('cookie')
|
Cookie = require('cookie')
|
||||||
logger = require "logger-sharelatex"
|
logger = require "logger-sharelatex"
|
||||||
|
|
||||||
|
@ -42,11 +44,16 @@ module.exports = ClsiCookieManager =
|
||||||
if !clsiCookiesEnabled
|
if !clsiCookiesEnabled
|
||||||
return callback()
|
return callback()
|
||||||
serverId = ClsiCookieManager._parseServerIdFromResponse(response)
|
serverId = ClsiCookieManager._parseServerIdFromResponse(response)
|
||||||
|
if rclient_secondary?
|
||||||
|
@_setServerIdInRedis rclient_secondary, project_id, serverId
|
||||||
|
@_setServerIdInRedis rclient, project_id, serverId, (err) ->
|
||||||
|
callback(err, serverId)
|
||||||
|
|
||||||
|
_setServerIdInRedis: (rclient, project_id, serverId, callback = (err) ->) ->
|
||||||
multi = rclient.multi()
|
multi = rclient.multi()
|
||||||
multi.set buildKey(project_id), serverId
|
multi.set buildKey(project_id), serverId
|
||||||
multi.expire buildKey(project_id), Settings.clsiCookie.ttl
|
multi.expire buildKey(project_id), Settings.clsiCookie.ttl
|
||||||
multi.exec (err)->
|
multi.exec callback
|
||||||
callback(err, serverId)
|
|
||||||
|
|
||||||
clearServerId: (project_id, callback = (err)->)->
|
clearServerId: (project_id, callback = (err)->)->
|
||||||
if !clsiCookiesEnabled
|
if !clsiCookiesEnabled
|
||||||
|
|
|
@ -34,9 +34,8 @@ describe "ClsiCookieManager", ->
|
||||||
ttl:Math.random()
|
ttl:Math.random()
|
||||||
key: "coooookie"
|
key: "coooookie"
|
||||||
@requires =
|
@requires =
|
||||||
"../../infrastructure/RedisWrapper":
|
"../../infrastructure/RedisWrapper": @RedisWrapper =
|
||||||
client: =>
|
client: => @redis
|
||||||
@redis
|
|
||||||
"settings-sharelatex": @settings
|
"settings-sharelatex": @settings
|
||||||
"request": @request
|
"request": @request
|
||||||
|
|
||||||
|
@ -107,6 +106,24 @@ describe "ClsiCookieManager", ->
|
||||||
@redisMulti.exec.called.should.equal false
|
@redisMulti.exec.called.should.equal false
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
it "should also set in the secondary if secondary redis is enabled", (done) ->
|
||||||
|
@redisSecondaryMulti =
|
||||||
|
set:sinon.stub()
|
||||||
|
expire:sinon.stub()
|
||||||
|
exec:sinon.stub()
|
||||||
|
@redis_secondary =
|
||||||
|
multi: => @redisSecondaryMulti
|
||||||
|
@settings.redis.clsi_cookie_secondary = {}
|
||||||
|
@RedisWrapper.client = sinon.stub()
|
||||||
|
@RedisWrapper.client.withArgs("clsi_cookie").returns(@redis)
|
||||||
|
@RedisWrapper.client.withArgs("clsi_cookie_secondary").returns(@redis_secondary)
|
||||||
|
@ClsiCookieManager = SandboxedModule.require modulePath, requires:@requires
|
||||||
|
@ClsiCookieManager._parseServerIdFromResponse = sinon.stub().returns("clsi-8")
|
||||||
|
@ClsiCookieManager.setServerId @project_id, @response, (err, serverId)=>
|
||||||
|
@redisSecondaryMulti.set.calledWith("clsiserver:#{@project_id}", "clsi-8").should.equal true
|
||||||
|
@redisSecondaryMulti.expire.calledWith("clsiserver:#{@project_id}", @settings.clsiCookie.ttl).should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
describe "getCookieJar", ->
|
describe "getCookieJar", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
Loading…
Reference in a new issue