Module: Sidekiq::Throttled
- Extended by:
- Utils
- Defined in:
- lib/sidekiq/throttled.rb,
lib/sidekiq/throttled/web.rb,
lib/sidekiq/throttled/fetch.rb,
lib/sidekiq/throttled/utils.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/configuration.rb,
lib/sidekiq/throttled/patches/queue.rb,
lib/sidekiq/throttled/queues_pauser.rb,
lib/sidekiq/throttled/strategy/base.rb,
lib/sidekiq/throttled/expirable_list.rb,
lib/sidekiq/throttled/web/summary_fix.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: Patches, Utils, Web, Worker Classes: Communicator, Configuration, Error
Constant Summary collapse
- VERSION =
Gem version
"0.12.0"
Class Method Summary collapse
- .configuration ⇒ Configuration
-
.setup! ⇒ void
Hooks throttler into sidekiq.
-
.throttled?(message) ⇒ Boolean
Tells whenever job is throttled or not.
Methods included from Utils
Class Method Details
.configuration ⇒ Configuration
52 53 54 |
# File 'lib/sidekiq/throttled.rb', line 52 def configuration @configuration ||= Configuration.new end |
.setup! ⇒ void
This method returns an undefined value.
Hooks throttler into sidekiq.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sidekiq/throttled.rb', line 59 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.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sidekiq/throttled.rb', line 78 def throttled?() = JSON.parse job = .fetch("class") { return false } jid = .fetch("jid") { return false } preload_constant! job Registry.get job do |strategy| return strategy.throttled?(jid, *["args"]) end false rescue false end |