Class: Ost::Queue
- Inherits:
-
Object
- Object
- Ost::Queue
- Defined in:
- lib/ost.rb
Instance Attribute Summary collapse
-
#backup ⇒ Object
readonly
Returns the value of attribute backup.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #each(&block) ⇒ Object (also: #pop)
-
#initialize(name) ⇒ Queue
constructor
A new instance of Queue.
- #items ⇒ Object
- #push(value) ⇒ Object (also: #<<)
- #redis ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(name) ⇒ Queue
Returns a new instance of Queue.
11 12 13 14 |
# File 'lib/ost.rb', line 11 def initialize(name) @key = Nest.new(:ost)[name] @backup = @key[Socket.gethostname][Process.pid] end |
Instance Attribute Details
#backup ⇒ Object (readonly)
Returns the value of attribute backup.
9 10 11 |
# File 'lib/ost.rb', line 9 def backup @backup end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/ost.rb', line 8 def key @key end |
Instance Method Details
#each(&block) ⇒ Object Also known as: pop
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ost.rb', line 20 def each(&block) @stopping = false loop do break if @stopping item = @key.brpoplpush(@backup, TIMEOUT) block.call(item) @backup.lpop end end |
#items ⇒ Object
38 39 40 |
# File 'lib/ost.rb', line 38 def items key.lrange(0, -1) end |
#push(value) ⇒ Object Also known as: <<
16 17 18 |
# File 'lib/ost.rb', line 16 def push(value) key.lpush(value) end |
#redis ⇒ Object
45 46 47 |
# File 'lib/ost.rb', line 45 def redis @redis ||= Redis.connect(Ost.) end |
#stop ⇒ Object
34 35 36 |
# File 'lib/ost.rb', line 34 def stop @stopping = true end |