Yet Another Throttler for Resque
gem install resque-yat
Here is an example how to limit rates with resque-yat:
class MyQueueClass @queue = :MyTestQueue # Specify rates for the queue # This limits the queue to 25 calls per hour or 2500 calls per day # It is assumed that the task will make at most 5 calls that # count against the limit. extend Resque::Plugins::Yat limit_rate 1.hour => 25, 1.day => 2500, :reserved_rate => 5 def self.perform # Call the api that we want to rate limit. some_data = some_third_party.call_api() # Every time we make a call, we let the throttler know about it. consume_rate end end
In the example above, tasks from the ‘MyTestQueue’ queue will only be processed if at least 5 calls can be made without exceeding the API limit (as specified by :reserved_rate). The task will actually make one call (specified by calling consume_rate), therefore once the task is finished, four calls would be automatically ‘reimbursed’
-
Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.
-
Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.
-
Fork the project.
-
Start a feature/bugfix branch.
-
Commit and push until you are happy with your contribution.
-
Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright © 2014 Exitround. See LICENSE.txt for further details.