LockManager.js 899 B

1234567891011121314151617181920212223242526
  1. const Settings = require('@overleaf/settings')
  2. const redis = require('@overleaf/redis-wrapper')
  3. const rclient = redis.createClient(Settings.redis.lock)
  4. const keys = Settings.redis.lock.key_schema
  5. const RedisLocker = require('@overleaf/redis-wrapper/RedisLocker')
  6. const { promisify } = require('@overleaf/promise-utils')
  7. module.exports = new RedisLocker({
  8. rclient,
  9. getKey(docId) {
  10. return keys.blockingKey({ doc_id: docId })
  11. },
  12. wrapTimeoutError(err, docId) {
  13. err.doc_id = docId
  14. return err
  15. },
  16. metricsPrefix: 'doc',
  17. lockTTLSeconds: Settings.redisLockTTLSeconds,
  18. })
  19. module.exports.promises = {
  20. checkLock: promisify(module.exports.checkLock.bind(module.exports)),
  21. getLock: promisify(module.exports.getLock.bind(module.exports)),
  22. releaseLock: promisify(module.exports.releaseLock.bind(module.exports)),
  23. tryLock: promisify(module.exports.tryLock.bind(module.exports)),
  24. }