overleaf/services/web/app/coffee/infrastructure/RateLimiter.coffee

12 lines
454 B
CoffeeScript
Raw Normal View History

settings = require("settings-sharelatex")
2014-09-26 09:52:00 -04:00
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)