Class: Ost::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/ost.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#backupObject (readonly)

Returns the value of attribute backup.



9
10
11
# File 'lib/ost.rb', line 9

def backup
  @backup
end

#keyObject (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

#itemsObject



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

#redisObject



45
46
47
# File 'lib/ost.rb', line 45

def redis
  @redis ||= Redis.connect(Ost.options)
end

#stopObject



34
35
36
# File 'lib/ost.rb', line 34

def stop
  @stopping = true
end