README.md in sidekiq-throttled-0.3.2 vs README.md in sidekiq-throttled-0.4.0

- old
+ new

@@ -10,25 +10,21 @@ ## Installation Add this line to your application's Gemfile: -```ruby +``` ruby gem "sidekiq-throttled" ``` And then execute: -``` -$ bundle -``` + $ bundle Or install it yourself as: -``` -$ gem install sidekiq-throttled -``` + $ gem install sidekiq-throttled ## Usage Add somewhere in your app's bootstrap (e.g. `config/initializers/sidekiq.rb` if @@ -82,9 +78,43 @@ def perform(user_id) # ... end end ``` + +You can also supply dynamic values for limits and periods by supplying a proc +for these values. The proc will be evaluated at the time the job is fetched +and will receive the same arguments that are passed to the job. + +``` ruby +class MyWorker + include Sidekiq::Worker + include Sidekiq::Throttled::Worker + + sidekiq_options :queue => :my_queue + + sidekiq_throttle({ + # Allow maximum 1000 concurrent jobs of this class at a time for VIPs and 10 for all other users. + :concurrency => { + :limit => ->(user_id) { User.vip?(user_id) ? 1_000 : 10 }, + :key_suffix => ->(user_id) { User.vip?(user_id) ? "vip" : "std" } + }, + # Allow 1000 jobs/hour to be processed for VIPs and 10/day for all others + :threshold => { + :limit => ->(user_id) { User.vip?(user_id) ? 1_000 : 10 }, + :period => ->(user_id) { User.vip?(user_id) ? 1.hour : 1.day }, + :key_suffix => ->(user_id) { User.vip?(user_id) ? "vip" : "std" } + }) + + def perform(user_id) + # ... + end +end +``` + +**NB** Don't forget to specify `:key_suffix` and make it return different values +if you are using dynamic limit/period options. Otherwise you risk getting into +some trouble. ## Supported Ruby Versions This library aims to support and is [tested against][travis] the following Ruby