For some applications you may be able to be more efficient by having your process request more than one token at once.
In this case, you can specify
acquire_partial to designate whether you'd like the acquisition to return if it is unable
to get all the tokens requests. For instance if you have a token bucket with only 19 tokens left and you request 30. With
acquire_partial = true
your limit check will succeed and you can get 19 from the
limiter = RateLimit::Limiter.new(apikey: "ACCT_ID|APIKEY") # only need to do this on startup limiter.upsert_limit("hit_api", 10, RateLimit::MINUTELY_ROLLING) limit_result = limiter.acquire("hit_api", 6, acquire_partial: true) limit_result.acquired.times do # will get 6 api.hit_it end limit_result = limiter.acquire("hit_api", 6, acquire_partial: true) limit_result.acquired.times do # will get 4 api.hit_it end
Read about Feature Flags