Merge pull request #16644 from overleaf/em-promisify-update-manager

Promisify UpdateManager

GitOrigin-RevId: 2c3e21ee6ef2454f79695ca8623c3d38720ff6bf
This commit is contained in:
Eric Mc Sween
2024-01-30 16:49:23 +00:00
committed by Copybot
parent 14bb3d7114
commit 8136036c33
17 changed files with 648 additions and 645 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ function histogram(key, value, buckets, labels = {}) {
}
class Timer {
constructor(key, sampleRate = 1, labels = {}, buckets) {
constructor(key, sampleRate = 1, labels = {}, buckets = undefined) {
if (typeof sampleRate === 'object') {
// called with (key, labels, buckets)
if (arguments.length === 3) {
+22
View File
@@ -1,3 +1,4 @@
const { promisify } = require('util')
const metrics = require('@overleaf/metrics')
const logger = require('@overleaf/logger')
const os = require('os')
@@ -64,6 +65,27 @@ module.exports = class RedisLocker {
// read-only copy for unit tests
this.unlockScript = UNLOCK_SCRIPT
this.promises = {
checkLock: promisify(this.checkLock.bind(this)),
getLock: promisify(this.getLock.bind(this)),
releaseLock: promisify(this.releaseLock.bind(this)),
// tryLock returns two values: gotLock and lockValue. We need to merge
// these two values into one for the promises version.
tryLock: id =>
new Promise((resolve, reject) => {
this.tryLock(id, (err, gotLock, lockValue) => {
if (err) {
reject(err)
} else if (!gotLock) {
resolve(null)
} else {
resolve(lockValue)
}
})
}),
}
}
// Use a signed lock value as described in