overleaf/services/web/app/coffee/infrastructure/RateLimiter.coffee
2014-09-26 14:52:00 +01:00

12 lines
No EOL
454 B
CoffeeScript

settings = require("settings-sharelatex")
redis = require("redis-sharelatex")
rclient = redis.createClient(settings.redis.web)
redback = require("redback").use(rclient)
module.exports =
addCount: (opts, callback = (opts, shouldProcess)->)->
ratelimit = redback.createRateLimit(opts.endpointName)
ratelimit.addCount opts.subjectName, opts.timeInterval, (err, callCount)->
shouldProcess = callCount < opts.throttle
callback(err, shouldProcess)