Sha256: bc42c8dd88f03d1eb9e3dae9db169af18f50b6a843f8be796a87a928956a8e57

Contents?: true

Size: 796 Bytes

Versions: 1

Compression:

Stored size: 796 Bytes

Contents

require "metacrunch/redis"

module Metacrunch
  class Redis::QueueDestination

    DEFAULT_OPTIONS = {
      save_on_close: false
    }

    def initialize(redis, queue_name, options = {})
      @redis = redis
      @queue_name = queue_name
      @options = DEFAULT_OPTIONS.merge(options)
    end

    def write(data)
      return if data.blank?

      @redis.rpush(@queue_name, data)
    rescue RuntimeError => e
      if e.message =~ /maxmemory/
        puts "Redis has reached maxmemory. Waiting 10 seconds and trying again..."
        sleep(10)
        retry
      else
        raise e
      end
    end

    def close
      if @redis
        begin
          @redis.bgsave if @options[:save_on_close]
        rescue Redis::CommandError ; end
        @redis.close
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
metacrunch-redis-1.1.0 lib/metacrunch/redis/queue_destination.rb