Class: MessageQueue::Kestrel

Inherits:
Base
  • Object
show all
Defined in:
lib/message_queue/kestrel.rb

Instance Attribute Summary

Attributes inherited from Base

#opts

Instance Method Summary collapse

Methods inherited from Base

#delete, #flush_all, #stop

Constructor Details

#initialize(opts) ⇒ Kestrel

Returns a new instance of Kestrel.



3
4
5
# File 'lib/message_queue/kestrel.rb', line 3

def initialize(opts)
  @servers = opts['servers']
end

Instance Method Details

#clientObject



28
29
30
# File 'lib/message_queue/kestrel.rb', line 28

def client
  @client ||= MemCache.new(servers) 
end

#confirm(queue) ⇒ Object



24
25
26
# File 'lib/message_queue/kestrel.rb', line 24

def confirm(queue)
  client.get("#{queue}/close")
end

#dequeue(queue) ⇒ Object



20
21
22
# File 'lib/message_queue/kestrel.rb', line 20

def dequeue(queue)
  client.get("#{queue}/open")
end

#enqueue(queue, data) ⇒ Object



16
17
18
# File 'lib/message_queue/kestrel.rb', line 16

def enqueue(queue, data)
  client.set(queue, data)
end

#queue_size(queue) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/message_queue/kestrel.rb', line 7

def queue_size(queue)
  size  = 0
  stats = client.stats
  servers.each do |server|
    size += stats[server]["queue_#{queue}_items"].to_i
  end
  size
end