Class: Metacrunch::Redis::QueueDestination

Inherits:
Object
  • Object
show all
Defined in:
lib/metacrunch/redis/queue_destination.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  save_on_close: false
}

Instance Method Summary collapse

Constructor Details

#initialize(redis, queue_name, options = {}) ⇒ QueueDestination

Returns a new instance of QueueDestination.



10
11
12
13
14
# File 'lib/metacrunch/redis/queue_destination.rb', line 10

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

Instance Method Details

#closeObject



30
31
32
33
34
35
36
37
# File 'lib/metacrunch/redis/queue_destination.rb', line 30

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

#write(data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/metacrunch/redis/queue_destination.rb', line 16

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