lib/sidekiq/capsule.rb in sidekiq-7.0.2 vs lib/sidekiq/capsule.rb in sidekiq-7.0.3

- old
+ new

@@ -19,16 +19,19 @@ include Sidekiq::Component attr_reader :name attr_reader :queues attr_accessor :concurrency + attr_reader :mode + attr_reader :weights def initialize(name, config) @name = name @config = config @queues = ["default"] @concurrency = config[:concurrency] + @mode = :strict end def fetcher @fetcher ||= begin inst = (config[:fetch_class] || Sidekiq::BasicFetch).new(self) @@ -39,17 +42,30 @@ def stop fetcher&.bulk_requeue([]) end + # Sidekiq checks queues in three modes: + # - :strict - all queues have 0 weight and are checked strictly in order + # - :weighted - queues have arbitrary weight between 1 and N + # - :random - all queues have weight of 1 def queues=(val) + @weights = {} @queues = Array(val).each_with_object([]) do |qstr, memo| arr = qstr arr = qstr.split(",") if qstr.is_a?(String) name, weight = arr + @weights[name] = weight.to_i [weight.to_i, 1].max.times do memo << name end + end + @mode = if @weights.values.all?(&:zero?) + :strict + elsif @weights.values.all? { |x| x == 1 } + :random + else + :weighted end end # Allow the middleware to be different per-capsule. # Avoid if possible and add middleware globally so all