README.md in sidekiq-throttled-0.16.1 vs README.md in sidekiq-throttled-0.16.2
- old
+ new
@@ -34,17 +34,17 @@
```
Load order can be an issue if you are using other Sidekiq plugins and/or middleware.
To prevent any problems, add the `.setup!` call to the bottom of your init file.
-Once you've done that you can include `Sidekiq::Throttled::Worker` to your
+Once you've done that you can include `Sidekiq::Throttled::Job` to your
job classes and configure throttling:
``` ruby
-class MyWorker
- include Sidekiq::Worker
- include Sidekiq::Throttled::Worker
+class MyJob
+ include Sidekiq::Job
+ include Sidekiq::Throttled::Job
sidekiq_options :queue => :my_queue
sidekiq_throttle(
# Allow maximum 10 concurrent jobs of this class at a time.
@@ -57,19 +57,33 @@
# ...
end
end
```
+**NOTE:** `Sidekiq::Throttled::Job` is aliased as `Sidekiq::Throttled::Worker`,
+thus if you're using Sidekiq prior 6.3.0 version, or you using `Sidekiq::Worker`
+naming convention, you can use the alias for consistency:
+
+``` ruby
+class MyWorker
+ include Sidekiq::Worker
+ include Sidekiq::Throttled::Worker
+
+ # ...
+end
+```
+
+
### Observer
You can specify an observer that will be called on throttling. To do so pass an
`:observer` option with callable object:
``` ruby
-class MyWorker
- include Sidekiq::Worker
- include Sidekiq::Throttled::Worker
+class MyJob
+ include Sidekiq::Job
+ include Sidekiq::Throttled::Job
MY_OBSERVER = lambda do |strategy, *args|
# do something
end
@@ -95,13 +109,13 @@
### Dynamic throttling
You can throttle jobs dynamically with `:key_suffix` option:
``` ruby
-class MyWorker
- include Sidekiq::Worker
- include Sidekiq::Throttled::Worker
+class MyJob
+ include Sidekiq::Job
+ include Sidekiq::Throttled::Job
sidekiq_options :queue => :my_queue
sidekiq_throttle(
# Allow maximum 10 concurrent jobs per user at a time.
@@ -117,13 +131,13 @@
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
+class MyJob
+ include Sidekiq::Job
+ include Sidekiq::Throttled::Job
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.
@@ -145,12 +159,12 @@
```
You also can use several different keys to throttle one worker.
``` ruby
-class MyWorker
- include Sidekiq::Worker
- include Sidekiq::Throttled::Worker
+class MyJob
+ include Sidekiq::Job
+ include Sidekiq::Throttled::Job
sidekiq_options :queue => :my_queue
sidekiq_throttle(
# Allow maximum 10 concurrent jobs per project at a time and maximum 2 jobs per user