Sha256: 43bcf85ce45a581e6fc03945b7bf94b35a9e37fa805f0760b13019caae94b148

Contents?: true

Size: 699 Bytes

Versions: 1

Compression:

Stored size: 699 Bytes

Contents

require_relative 'util'

module Upperkut
  class Strategy
    include Upperkut::Util

    attr_accessor :worker, :redis

    def initialize(worker, redis)
      self.worker = worker
      self.redis  = redis
    end

    def push_items(items = [])
      return false if items.empty?
      redis.lpush(key, encode_json_items(items))
    end

    def fetch_items(batch_size = 1000)
      stop = [batch_size, size].min

      items = redis.multi do
        stop.times do
          redis.lpop(key)
        end
      end

      decode_json_items(items)
    end

    def size
      redis.llen(key)
    end

    private

    def key
      "upperkut:buffers:#{to_underscore(worker.name)}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
upperkut-0.1.0 lib/upperkut/strategy.rb