Sha256: 59493269083dc6fd281d9c06d1a5c5b596d6adbfffa30730b6cffa0da2292cf9

Contents?: true

Size: 672 Bytes

Versions: 4

Compression:

Stored size: 672 Bytes

Contents

module AtomicSidekiq
  class InFlightQueue
    def initialize
      @keymaker = InFlightKeymaker.new(AtomicFetch::IN_FLIGHT_KEY_PREFIX)
    end

    def list
      keys = list_keys
      retrieve_jobs(keys)
    end

    private

    attr_reader :keymaker

    def list_keys
      matcher = keymaker.matcher
      result = []
      it = 0
      loop do
        it, keys = Sidekiq.redis { |conn| conn.scan(it, match: matcher) }
        result.concat(keys)
        it = it.to_i
        break if it.zero?
      end
      result
    end

    def retrieve_jobs(keys)
      Sidekiq.redis do |conn|
        keys.map { |key| JSON.parse(conn.get(key)) }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
atomic-sidekiq-1.2.0 lib/atomic_sidekiq/in_flight_queue.rb
atomic-sidekiq-1.1.4 lib/atomic_sidekiq/in_flight_queue.rb
atomic-sidekiq-1.1.3 lib/atomic_sidekiq/in_flight_queue.rb
atomic-sidekiq-1.1.2 lib/atomic_sidekiq/in_flight_queue.rb