2014-03-03 06:46:40 -05:00
|
|
|
settings = require("settings-sharelatex")
|
2014-09-26 09:52:00 -04:00
|
|
|
redis = require("redis-sharelatex")
|
|
|
|
rclient = redis.createClient(settings.redis.web)
|
2014-03-03 06:46:40 -05:00
|
|
|
redback = require("redback").use(rclient)
|
2014-02-28 12:59:54 -05:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
addCount: (opts, callback = (opts, shouldProcess)->)->
|
|
|
|
ratelimit = redback.createRateLimit(opts.endpointName)
|
|
|
|
ratelimit.addCount opts.subjectName, opts.timeInterval, (err, callCount)->
|
|
|
|
shouldProcess = callCount < opts.throttle
|
2015-02-05 05:18:18 -05:00
|
|
|
callback(err, shouldProcess)
|
|
|
|
|
|
|
|
clearRateLimit: (endpointName, subject, callback) ->
|
|
|
|
rclient.del "#{endpointName}:#{subject}", callback
|