Files
overleaf-cep/services/web/app/src/infrastructure/LockManager.js
Eric Mc Sween e73fdfba63 Merge pull request #18906 from overleaf/em-migrate-existing-histories-2
History ranges migration script - second attempt

GitOrigin-RevId: 60a2c04e2a72e76a58e9e179fefc4186a96fde32
2024-06-19 08:05:02 +00:00

37 lines
1.0 KiB
JavaScript

const settings = require('@overleaf/settings')
const RedisWrapper = require('./RedisWrapper')
const rclient = RedisWrapper.client('lock')
const RedisWebLocker = require('@overleaf/redis-wrapper/RedisWebLocker')
// this method creates a lock manager with the provided timeout options
function createLockManager(options) {
return new RedisWebLocker({
rclient,
getKey(namespace, id) {
return `lock:web:${namespace}:${id}`
},
options,
})
}
// this is the default lock manager for web
const LockManager = createLockManager(settings.lockManager)
// this method creates a lock manager with a configurable timeout
// it shares the lock keys with the default lock manager
LockManager.withTimeout = function (timeout) {
const overrides = {
redisLockExpiry: timeout, // in seconds
slowExecutionThreshold: 0.5 * timeout * 1000, // in ms
}
const lockManagerSettingsWithTimeout = Object.assign(
{},
settings.lockManager,
overrides
)
return createLockManager(lockManagerSettingsWithTimeout)
}
module.exports = LockManager