Sha256: ade076725862ac4be423a863e10a8822dcbe352eca87a04b254f6e4c657b8d2d
Contents?: true
Size: 1.25 KB
Versions: 6
Compression:
Stored size: 1.25 KB
Contents
require 'sidekiq' require 'forwardable' class Sidekiq::LimitFetch autoload :UnitOfWork, 'sidekiq/limit_fetch/unit_of_work' require_relative 'limit_fetch/redis' require_relative 'limit_fetch/singleton' require_relative 'limit_fetch/queues' require_relative 'limit_fetch/global/semaphore' require_relative 'limit_fetch/global/selector' require_relative 'limit_fetch/global/monitor' require_relative 'extensions/queue' include Redis Sidekiq.options[:fetch] = self def self.bulk_requeue(*args) Sidekiq::BasicFetch.bulk_requeue *args end def initialize(options) Global::Monitor.start! @queues = Queues.new options.merge(namespace: determine_namespace) end def retrieve_work queue, message = fetch_message UnitOfWork.new queue, message if message end private def fetch_message queue, _ = redis_brpop *@queues.acquire, Sidekiq::Fetcher::TIMEOUT ensure @queues.release_except queue end def redis_brpop(*args) return if args.size < 2 query = -> redis { redis.brpop *args } if busy_local_queues.any? {|queue| not args.include? queue.rname } nonblocking_redis(&query) else redis(&query) end end def busy_local_queues Sidekiq::Queue.instances.select(&:local_busy?) end end
Version data entries
6 entries across 6 versions & 1 rubygems