mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
23 lines
727 B
CoffeeScript
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")
|
|
|