Module: Sidekiq::Throttled
- Defined in:
- lib/sidekiq/throttled.rb,
lib/sidekiq/throttled/job.rb,
lib/sidekiq/throttled/web.rb,
lib/sidekiq/throttled/config.rb,
lib/sidekiq/throttled/errors.rb,
lib/sidekiq/throttled/worker.rb,
lib/sidekiq/throttled/version.rb,
lib/sidekiq/throttled/cooldown.rb,
lib/sidekiq/throttled/registry.rb,
lib/sidekiq/throttled/strategy.rb,
lib/sidekiq/throttled/web/stats.rb,
lib/sidekiq/throttled/expirable_set.rb,
lib/sidekiq/throttled/strategy/base.rb,
lib/sidekiq/throttled/middlewares/server.rb,
lib/sidekiq/throttled/strategy/threshold.rb,
lib/sidekiq/throttled/patches/basic_fetch.rb,
lib/sidekiq/throttled/patches/super_fetch.rb,
lib/sidekiq/throttled/strategy_collection.rb,
lib/sidekiq/throttled/strategy/concurrency.rb,
lib/sidekiq/throttled/patches/throttled_retriever.rb
Overview
Concurrency and threshold throttling for Sidekiq.
Just add somewhere in your bootstrap:
require "sidekiq/throttled"
Once you’ve done that you can include Job to your job classes and configure throttling:
class MyJob
include Sidekiq::Job
include Sidekiq::Throttled::Job
: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: Job, Middlewares, Patches, Registry, Web Classes: Config, Cooldown, Error, ExpirableSet, Strategy, StrategyCollection
Constant Summary collapse
- Worker =
A new module, Sidekiq::Job, was added in Sidekiq version 6.3.0 as a simple alias for Sidekiq::Worker as the term “worker” was considered too generic and confusing. Many people call a Sidekiq process a “worker” whereas others call the thread that executes jobs a “worker”.
Job
- VERSION =
Gem version
"1.3.0"
Class Attribute Summary collapse
- .cooldown ⇒ Cooldown? readonly
Class Method Summary collapse
- .configure {|config| ... } ⇒ Object
-
.setup! ⇒ Object
deprecated
Deprecated.
Will be removed in 2.0.0
-
.throttled?(message) ⇒ Boolean
Tells whenever job is throttled or not.
Class Attribute Details
.cooldown ⇒ Cooldown? (readonly)
54 55 56 |
# File 'lib/sidekiq/throttled.rb', line 54 def cooldown @cooldown end |
Class Method Details
.configure {|config| ... } ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sidekiq/throttled.rb', line 62 def configure MUTEX.synchronize do config = @config.dup yield config @config = config.freeze @cooldown = Cooldown[@config] end end |
.setup! ⇒ Object
Deprecated.
Will be removed in 2.0.0
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/sidekiq/throttled.rb', line 94 def setup! warn "Sidekiq::Throttled.setup! was deprecated" Sidekiq.configure_server do |config| config.server_middleware do |chain| chain.remove(Sidekiq::Throttled::Middlewares::Server) chain.add(Sidekiq::Throttled::Middlewares::Server) end end end |
.throttled?(message) ⇒ Boolean
Tells whenever job is throttled or not.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sidekiq/throttled.rb', line 77 def throttled?() = Sidekiq.load_json() job = .fetch("wrapped") { ["class"] } jid = ["jid"] return false unless job && jid Registry.get(job) do |strategy| return strategy.throttled?(jid, *["args"]) end false rescue StandardError false end |