Module: Sidekiq::Throttled
- Defined in:
- lib/sidekiq/throttled.rb,
lib/sidekiq/throttled/web.rb,
lib/sidekiq/throttled/fetch.rb,
lib/sidekiq/throttled/errors.rb,
lib/sidekiq/throttled/worker.rb,
lib/sidekiq/throttled/version.rb,
lib/sidekiq/throttled/registry.rb,
lib/sidekiq/throttled/strategy.rb,
lib/sidekiq/throttled/web/stats.rb,
lib/sidekiq/throttled/middleware.rb,
lib/sidekiq/throttled/queue_name.rb,
lib/sidekiq/throttled/communicator.rb,
lib/sidekiq/throttled/queues_pauser.rb,
lib/sidekiq/throttled/strategy/script.rb,
lib/sidekiq/throttled/fetch/unit_of_work.rb,
lib/sidekiq/throttled/strategy/threshold.rb,
lib/sidekiq/throttled/strategy/concurrency.rb,
lib/sidekiq/throttled/communicator/listener.rb,
lib/sidekiq/throttled/communicator/callbacks.rb
Overview
Concurrency and threshold throttling for Sidekiq.
Just add somewhere in your bootstrap:
require "sidekiq/throttled"
Sidekiq::Throttled.setup!
Once you’ve done that you can include Worker to your job classes and configure throttling:
class MyWorker
include Sidekiq::Worker
include Sidekiq::Throttled::Worker
:queue => :my_queue
sidekiq_throttle({
# Allow maximum 10 concurrent jobs of this class at a time.
:concurrency => { :limit => 10 },
# Allow maximum 1K jobs being processed within one hour window.
:threshold => { :limit => 1_000, :period => 1.hour }
})
def perform
# ...
end
end
Defined Under Namespace
Modules: Worker Classes: Communicator, Error
Constant Summary collapse
- VERSION =
Gem version
"0.6.5".freeze
Class Method Summary collapse
-
.pause!(queue) ⇒ void
Pauses given ‘queue`.
-
.paused_queues ⇒ Array<String>
Returns list of paused queues.
-
.resume!(queue) ⇒ void
Resumes given ‘queue`.
-
.setup! ⇒ void
Hooks throttler into sidekiq.
-
.throttled?(message) ⇒ Boolean
Tells whenever job is throttled or not.
Class Method Details
.pause!(queue) ⇒ void
This method returns an undefined value.
Pauses given ‘queue`.
62 63 64 |
# File 'lib/sidekiq/throttled.rb', line 62 def pause!(queue) QueuesPauser.instance.pause!(queue) end |
.paused_queues ⇒ Array<String>
Returns list of paused queues.
72 73 74 |
# File 'lib/sidekiq/throttled.rb', line 72 def paused_queues QueuesPauser.instance.paused_queues end |
.resume!(queue) ⇒ void
This method returns an undefined value.
Resumes given ‘queue`.
67 68 69 |
# File 'lib/sidekiq/throttled.rb', line 67 def resume!(queue) QueuesPauser.instance.resume!(queue) end |
.setup! ⇒ void
This method returns an undefined value.
Hooks throttler into sidekiq.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sidekiq/throttled.rb', line 46 def setup! Communicator.instance.setup! QueuesPauser.instance.setup! Sidekiq.configure_server do |config| require "sidekiq/throttled/fetch" Sidekiq.[:fetch] = Sidekiq::Throttled::Fetch require "sidekiq/throttled/middleware" config.server_middleware do |chain| chain.add Sidekiq::Throttled::Middleware end end end |
.throttled?(message) ⇒ Boolean
Tells whenever job is throttled or not.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sidekiq/throttled.rb', line 80 def throttled?() = JSON.parse job = .fetch("class".freeze) { return false } jid = .fetch("jid".freeze) { return false } Registry.get job do |strategy| return strategy.throttled?(jid, *["args"]) end false rescue false end |