overleaf/services/web/app/coffee/Features/Cooldown/CooldownManager.coffee

24 lines
727 B
CoffeeScript
Raw Normal View History

RedisWrapper = require('../../infrastructure/RedisWrapper')
rclient = RedisWrapper.client('cooldown')
logger = require('logger-sharelatex')
COOLDOWN_IN_SECONDS = 60 * 10
module.exports = CooldownManager =
_buildKey: (projectId) ->
"Cooldown:{#{projectId}}"
putProjectOnCooldown: (projectId, callback=(err)->) ->
2017-05-10 10:16:36 -04:00
logger.log {projectId}, "[Cooldown] putting project on cooldown for #{COOLDOWN_IN_SECONDS} seconds"
rclient.set(CooldownManager._buildKey(projectId), '1', 'EX', COOLDOWN_IN_SECONDS, callback)
isProjectOnCooldown: (projectId, callback=(err, isOnCooldown)->) ->
rclient.get CooldownManager._buildKey(projectId), (err, result) ->
if err?
return callback(err)
callback(null, result == "1")