https://github.com/julienxx/resque-waiting-room
Resque plugin that throttles your jobs
https://github.com/julienxx/resque-waiting-room
rate-limiting resque resque-plugin ruby
Last synced: about 1 month ago
JSON representation
Resque plugin that throttles your jobs
- Host: GitHub
- URL: https://github.com/julienxx/resque-waiting-room
- Owner: julienXX
- License: mit
- Created: 2012-02-08T14:31:03.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2018-02-07T09:18:32.000Z (over 7 years ago)
- Last Synced: 2024-10-13T14:11:32.252Z (about 1 year ago)
- Topics: rate-limiting, resque, resque-plugin, ruby
- Language: Ruby
- Homepage:
- Size: 55.7 KB
- Stars: 33
- Watchers: 5
- Forks: 14
- Open Issues: 1
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE
Awesome Lists containing this project
README
Resque Waiting Room
===================
A [Resque][rq] plugin. Requires Resque >= 1.19 and a >= 1.9 Ruby (MRI, JRuby or Rubinius).
If you want to limit the number of performs of a job for a given period, extend it
with this module.
## Installation
Add this line to your application's Gemfile:
gem 'resque-waiting-room'
And then execute:
$ bundle
Or install it yourself as:
$ gem install resque-waiting-room
## Usage
#### Example -- 10 jobs processed every 30 seconds max
require 'resque/plugins/waiting_room'
class UpdateDataFromExternalAPI
extend Resque::Plugins::WaitingRoom
# This job can be performed 10 times every 30 seconds
can_be_performed times: 10, period: 30
def self.perform(repo_id)
blah
end
end
If 10 UpdateDataFromExternalAPI jobs have been performed in 20
seconds, for the next 10 seconds UpdateDataFromExternalAPI jobs
will be placed in the waiting_room queue and processed when possible.
When the first 30 seconds are elapsed, the counter is set back to 0
and 10 jobs can be performed again.
You got to manually tweak the queue names in your workers though.
## Testing
We include a matcher
require 'spec/support/matchers'
describe MyJob do
it 'is rate limited' do
MyJob.should be_only_performed(times: 100, period: 300)
end
end
Run tests with the following command
bundle exec rake
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
## Thanks to the following people for helping out ##
- Thomas Devol [@socialchorus](https://github.com/socialchorus) for adding the RSpec matcher
- Max Dunn [@maxdunn210](https://github.com/maxdunn210) for making me switch Resque 2 specific code in it's own branch
- Jeff Durand [@johnnyiller](https://github.com/johnnyiller) for the update of has_remaining_performs_key using the latest form set and the fix for a rare ttl bug
- Tatsuya Takamura [@ttakamura](https://github.com/ttakamura) for raising the issue on the rare ttl bug
- Omry Zobel [@omryYotpo](https://github.com/omryYotpo) for allowing some customization of the redis key
[rq]: http://github.com/resque/resque
[](https://travis-ci.org/julienXX/resque-waiting-room) [](https://codeclimate.com/github/julienXX/resque-waiting-room)