Sha256: 8a92d349dce89e6a0708a59d2f5f4ea471a9d739e6969505991c4f578bddcaea

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

require 'sidekiq'
require 'sidekiq/fetch'

class Sidekiq::LimitFetch
  require_relative 'limit_fetch/unit_of_work'
  require_relative 'limit_fetch/singleton'
  require_relative 'limit_fetch/queues'
  require_relative 'limit_fetch/local/semaphore'
  require_relative 'limit_fetch/local/selector'
  require_relative 'limit_fetch/global/semaphore'
  require_relative 'limit_fetch/global/selector'
  require_relative 'limit_fetch/global/monitor'
  require_relative 'extensions/queue'

  Sidekiq.options[:fetch] = self

  def self.bulk_requeue(jobs)
    Sidekiq::BasicFetch.bulk_requeue jobs
  end

  def initialize(options)
    Global::Monitor.start! if options[:global]
    @queues = Queues.new options
  end

  def retrieve_work
    queue, message = fetch_message
    UnitOfWork.new queue, message if message
  end

  private

  def fetch_message
    queue, _ = redis_blpop *@queues.acquire, Sidekiq::Fetcher::TIMEOUT
  ensure
    @queues.release_except queue
  end

  def redis_blpop(*args)
    return if args.size < 2
    Sidekiq.redis {|it| it.blpop *args }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sidekiq-limit_fetch-1.4 lib/sidekiq/limit_fetch.rb
sidekiq-limit_fetch-1.3 lib/sidekiq/limit_fetch.rb
sidekiq-limit_fetch-1.2 lib/sidekiq/limit_fetch.rb
sidekiq-limit_fetch-1.1 lib/sidekiq/limit_fetch.rb
sidekiq-limit_fetch-1.0 lib/sidekiq/limit_fetch.rb
sidekiq-limit_fetch-0.9 lib/sidekiq/limit_fetch.rb