overleaf/services/web/app/coffee/Features/Cooldown/CooldownManager.coffee
Shane Kilkelly b8e4cafd81 Fix log line
2017-05-10 15:16:36 +01:00

23 lines
727 B
CoffeeScript

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)->) ->
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")