mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 05:41:33 +02:00
3eb6609ddc
Promisify TpdsUpdateHandler GitOrigin-RevId: 3955a535e8d0b702751883d05c21c4c78717fed5
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
/* eslint-disable
|
|
n/handle-callback-err,
|
|
max-len,
|
|
*/
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
// Fix any style issues and re-enable lint.
|
|
/*
|
|
* decaffeinate suggestions:
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
* DS207: Consider shorter variations of null checks
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
*/
|
|
let CooldownManager
|
|
const RedisWrapper = require('../../infrastructure/RedisWrapper')
|
|
const rclient = RedisWrapper.client('cooldown')
|
|
const logger = require('@overleaf/logger')
|
|
const { promisifyAll } = require('../../util/promises')
|
|
|
|
const COOLDOWN_IN_SECONDS = 60 * 10
|
|
|
|
module.exports = CooldownManager = {
|
|
_buildKey(projectId) {
|
|
return `Cooldown:{${projectId}}`
|
|
},
|
|
|
|
putProjectOnCooldown(projectId, callback) {
|
|
if (callback == null) {
|
|
callback = function () {}
|
|
}
|
|
logger.debug(
|
|
{ projectId },
|
|
`[Cooldown] putting project on cooldown for ${COOLDOWN_IN_SECONDS} seconds`
|
|
)
|
|
return rclient.set(
|
|
CooldownManager._buildKey(projectId),
|
|
'1',
|
|
'EX',
|
|
COOLDOWN_IN_SECONDS,
|
|
callback
|
|
)
|
|
},
|
|
|
|
isProjectOnCooldown(projectId, callback) {
|
|
if (callback == null) {
|
|
callback = function () {}
|
|
}
|
|
return rclient.get(
|
|
CooldownManager._buildKey(projectId),
|
|
function (err, result) {
|
|
if (err != null) {
|
|
return callback(err)
|
|
}
|
|
return callback(null, result === '1')
|
|
}
|
|
)
|
|
},
|
|
}
|
|
|
|
module.exports.promises = promisifyAll(module.exports, {
|
|
without: ['_buildKey'],
|
|
})
|