Sha256: 4c0f3d2773a9e1b79bd2a619ef20e40a76f3e2bc1c881612f9f041b00b0a72da
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
class Sidekiq::LimitFetch class Queues THREAD_KEY = :acquired_queues def initialize(options) @queues = options[:queues] options[:strict] ? strict_order! : weighted_order! set_limits options[:limits] set_blocks options[:blocking] end def acquire selector.acquire(ordered_queues) .tap {|it| save it } .map {|it| "queue:#{it}" } end def release_except(full_name) queues = restore queues.delete full_name[/queue:(.*)/, 1] if full_name selector.release queues end private def selector Global::Selector end def set_limits(limits) return unless limits limits.each do |name, limit| Sidekiq::Queue[name].limit = limit end end def set_blocks(blocks) blocks.to_a.each do |it| if it.is_a? Array it.each {|name| Sidekiq::Queue[name].block_except it } else Sidekiq::Queue[it].block end end end def strict_order! @queues.uniq! def ordered_queues; @queues end end def weighted_order! def ordered_queues; @queues.shuffle.uniq end end def save(queues) Thread.current[THREAD_KEY] = queues end def restore Thread.current[THREAD_KEY] || [] ensure Thread.current[THREAD_KEY] = nil end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-limit_fetch-2.0 | lib/sidekiq/limit_fetch/queues.rb |
sidekiq-limit_fetch-1.7 | lib/sidekiq/limit_fetch/queues.rb |