Class: ReliableQueue
- Inherits:
-
Object
- Object
- ReliableQueue
- Includes:
- Enumerable
- Defined in:
- lib/reliable_queue_rb/reliable_queue.rb
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
-
#working_queue ⇒ Object
readonly
Returns the value of attribute working_queue.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(queue, redis) ⇒ ReliableQueue
constructor
A new instance of ReliableQueue.
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
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
4 5 6 |
# File 'lib/reliable_queue_rb/reliable_queue.rb', line 4 def queue @queue end |
#redis ⇒ Object (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_queue ⇒ Object (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
#each ⇒ Object
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 |