lib/sidekiq/throttled.rb in sidekiq-throttled-0.16.1 vs lib/sidekiq/throttled.rb in sidekiq-throttled-0.16.2

- old
+ new

@@ -20,16 +20,16 @@ # Just add somewhere in your bootstrap: # # require "sidekiq/throttled" # Sidekiq::Throttled.setup! # - # 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: # - # 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. @@ -60,11 +60,11 @@ def setup! Communicator.instance.setup! QueuesPauser.instance.setup! Sidekiq.configure_server do |config| - setup_strategy! + setup_strategy!(config) require "sidekiq/throttled/middleware" config.server_middleware do |chain| chain.add Sidekiq::Throttled::Middleware end @@ -92,18 +92,23 @@ end private # @return [void] - def setup_strategy! + def setup_strategy!(sidekiq_config) require "sidekiq/throttled/fetch" + sidekiq_version = Gem::Version.new(Sidekiq::VERSION) + + # https://github.com/mperham/sidekiq/commit/67daa7a408b214d593100f782271ed108686c147 + sidekiq_config = sidekiq_config.options if sidekiq_version < Gem::Version.new("6.5.0") + # https://github.com/mperham/sidekiq/commit/fce05c9d4b4c0411c982078a4cf3a63f20f739bc - Sidekiq.options[:fetch] = + sidekiq_config[:fetch] = if Gem::Version.new(Sidekiq::VERSION) < Gem::Version.new("6.1.0") Sidekiq::Throttled::Fetch else - Sidekiq::Throttled::Fetch.new(Sidekiq.options) + Sidekiq::Throttled::Fetch.new(sidekiq_config) end end # Tries to preload constant by it's name once. #