Module: SidekiqBus
- Defined in:
- lib/sidekiq-bus.rb,
lib/sidekiq_bus/server.rb,
lib/sidekiq_bus/version.rb,
lib/sidekiq_bus/middleware/retry.rb
Defined Under Namespace
Modules: Middleware, Server
Constant Summary collapse
- VERSION =
'0.9.0'
Class Method Summary collapse
-
.generate_weighted_queues(overrides: {}, default: 1) ⇒ Object
This method will analyze the current queues and generate an array that can operate as the sidekiq queues configuration.
Class Method Details
.generate_weighted_queues(overrides: {}, default: 1) ⇒ Object
This method will analyze the current queues and generate an array that can operate as the sidekiq queues configuration. It should be based on how The sidekiq CLI builds weighted queues.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sidekiq-bus.rb', line 18 def self.generate_weighted_queues(overrides: {}, default: 1) # Gathers all queues and overrides as strictly strings queues = Set.new(QueueBus::TaskManager.new(false).queue_names.map(&:to_s)) overrides = overrides.each_with_object({}) { |(q, w), h| h[q.to_s] = w } overrides.default = default # Also pitches-in for driving the bus. queues << 'bus_incoming' # Make sure every queue from the overrides is included queues += overrides.keys entry = Struct.new(:queue, :weight) # Map all queue names to their weights and returns them as entries entries = queues.map { |q| entry.new(q, [1, overrides[q]].max) } # Sorts by weight to provide a visual indication of queue order in sidekiq # UI. Otherwise they can appear in various orders. They will be sorted # from greatest to least weight. The negative sign on the weight is key to # making this work. entries = entries.sort_by { |e| [-e.weight, e.queue] } # Creates an array of N length with the same queue name (N=weight) then # flattened into a single array entries.flat_map { |e| Array.new(e.weight, e.queue) } end |