From 508a95c19b1e0646d9c750c24ea8940c7d90d4c7 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 6 Jul 2016 11:50:02 +0100 Subject: [PATCH] Use the main redis instance for locks --- services/document-updater/app/coffee/LockManager.coffee | 7 +++++-- .../test/unit/coffee/LockManager/CheckingTheLock.coffee | 4 +--- .../test/unit/coffee/LockManager/ReleasingTheLock.coffee | 4 +--- .../test/unit/coffee/LockManager/getLockTests.coffee | 4 +--- .../test/unit/coffee/LockManager/tryLockTests.coffee | 4 +--- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/services/document-updater/app/coffee/LockManager.coffee b/services/document-updater/app/coffee/LockManager.coffee index a1ed9292e9..aae60f123d 100644 --- a/services/document-updater/app/coffee/LockManager.coffee +++ b/services/document-updater/app/coffee/LockManager.coffee @@ -1,7 +1,7 @@ metrics = require('./Metrics') Settings = require('settings-sharelatex') -rclient = require("./RedisBackend").createClient() -keys = require('./RedisKeyBuilder') +redis = require("redis-sharelatex") +rclient = redis.createClient(Settings.redis.web) logger = require "logger-sharelatex" os = require "os" crypto = require "crypto" @@ -11,6 +11,9 @@ PID = process.pid RND = crypto.randomBytes(4).toString('hex') COUNT = 0 +keys = + blockingKey: ({doc_id}) -> "Blocking:#{doc_id}" + module.exports = LockManager = LOCK_TEST_INTERVAL: 50 # 50ms between each test of the lock MAX_LOCK_WAIT_TIME: 10000 # 10s maximum time to spend trying to get the lock diff --git a/services/document-updater/test/unit/coffee/LockManager/CheckingTheLock.coffee b/services/document-updater/test/unit/coffee/LockManager/CheckingTheLock.coffee index ea69dcff52..f6670c8b35 100644 --- a/services/document-updater/test/unit/coffee/LockManager/CheckingTheLock.coffee +++ b/services/document-updater/test/unit/coffee/LockManager/CheckingTheLock.coffee @@ -14,9 +14,7 @@ describe 'LockManager - checking the lock', ()-> mocks = "logger-sharelatex": log:-> - "./RedisKeyBuilder": - blockingKey: ({doc_id}) -> "Blocking:#{doc_id}" - "./RedisBackend": + "redis-sharelatex": createClient : ()-> auth:-> exists: existsStub diff --git a/services/document-updater/test/unit/coffee/LockManager/ReleasingTheLock.coffee b/services/document-updater/test/unit/coffee/LockManager/ReleasingTheLock.coffee index 3260c2fea9..ed502fb587 100644 --- a/services/document-updater/test/unit/coffee/LockManager/ReleasingTheLock.coffee +++ b/services/document-updater/test/unit/coffee/LockManager/ReleasingTheLock.coffee @@ -12,9 +12,7 @@ describe 'LockManager - releasing the lock', ()-> evalStub = sinon.stub().yields(1) mocks = "logger-sharelatex": log:-> - "./RedisKeyBuilder": - blockingKey: ({doc_id}) -> "Blocking:#{doc_id}" - "./RedisBackend": + "redis-sharelatex": createClient : ()-> auth:-> eval: evalStub diff --git a/services/document-updater/test/unit/coffee/LockManager/getLockTests.coffee b/services/document-updater/test/unit/coffee/LockManager/getLockTests.coffee index 89c08afc2f..84cc3208a3 100644 --- a/services/document-updater/test/unit/coffee/LockManager/getLockTests.coffee +++ b/services/document-updater/test/unit/coffee/LockManager/getLockTests.coffee @@ -8,9 +8,7 @@ describe 'LockManager - getting the lock', -> beforeEach -> @LockManager = SandboxedModule.require modulePath, requires: "logger-sharelatex": log:-> - "./RedisKeyBuilder": - blockingKey: ({doc_id}) -> "Blocking:#{doc_id}" - "./RedisBackend": + "redis-sharelatex": createClient : () => auth:-> "./Metrics": {inc: () ->} diff --git a/services/document-updater/test/unit/coffee/LockManager/tryLockTests.coffee b/services/document-updater/test/unit/coffee/LockManager/tryLockTests.coffee index 55af920469..33c3eb3d51 100644 --- a/services/document-updater/test/unit/coffee/LockManager/tryLockTests.coffee +++ b/services/document-updater/test/unit/coffee/LockManager/tryLockTests.coffee @@ -8,9 +8,7 @@ describe 'LockManager - trying the lock', -> beforeEach -> @LockManager = SandboxedModule.require modulePath, requires: "logger-sharelatex": log:-> - "./RedisKeyBuilder": - blockingKey: ({doc_id}) -> "Blocking:#{doc_id}" - "./RedisBackend": + "redis-sharelatex": createClient : () => auth:-> set: @set = sinon.stub()