class Sidekiq::Apriori::Prioritizer

Public Instance Methods

call(worker, msg, queue, redis_pool = nil) { || ... } click to toggle source
# File lib/sidekiq-apriori/middleware/prioritizer.rb, line 5
def call(worker, msg, queue, redis_pool = nil)
  options   = msg["args"].last if msg["args"].respond_to?(:last)
  priority  = options[:priority] if options.is_a?(Hash) && options.has_key?(:priority)

  if priorities.include?(priority)
    msg["queue"] = queue.to_s.sub(priority_regexp,"_#{priority}")
  end

  yield
end
priorities() click to toggle source
# File lib/sidekiq-apriori/middleware/prioritizer.rb, line 16
def priorities
  Sidekiq::Apriori::PRIORITIES.compact
end
priority_regexp() click to toggle source
# File lib/sidekiq-apriori/middleware/prioritizer.rb, line 20
def priority_regexp
  /(_(#{priorities.join('|')}))*$/
end