Class: ReliableQueue

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/reliable_queue_rb/reliable_queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue, redis) ⇒ ReliableQueue

Returns a new instance of ReliableQueue.



6
7
8
9
10
11
12
# File 'lib/reliable_queue_rb/reliable_queue.rb', line 6

def initialize(queue, redis)
  @queue = queue
  @redis = redis
  @working_queue = "#{queue}.working_on"

  requeue_unfinished_work
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



4
5
6
# File 'lib/reliable_queue_rb/reliable_queue.rb', line 4

def queue
  @queue
end

#redisObject (readonly)

Returns the value of attribute redis.



4
5
6
# File 'lib/reliable_queue_rb/reliable_queue.rb', line 4

def redis
  @redis
end

#working_queueObject (readonly)

Returns the value of attribute working_queue.



4
5
6
# File 'lib/reliable_queue_rb/reliable_queue.rb', line 4

def working_queue
  @working_queue
end

Instance Method Details

#eachObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/reliable_queue_rb/reliable_queue.rb', line 14

def each
  return enum_for(:each) unless block_given?

  loop do
    reply = redis.brpoplpush(queue, working_queue, 30)
    next unless reply

    yield reply
    redis.lrem(working_queue, 0, reply)
  end
end