Class: Sparrow::Queue

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

Class Method Summary collapse

Class Method Details

.add_message(queue_name, value) ⇒ Object



17
18
19
# File 'lib/sparrow/queue.rb', line 17

def add_message(queue_name, value)
  self.get_queue(queue_name).push(value)
end

.delete(queue_name) ⇒ Object



21
22
23
24
25
26
# File 'lib/sparrow/queue.rb', line 21

def delete(queue_name)
  queue = self.get_queue(queue_name)
  queue.clear
  @@queues.delete(queue_name)
  true        
end

.delete_allObject



28
29
30
31
# File 'lib/sparrow/queue.rb', line 28

def delete_all
  @@queues.each {|name, q| q.clear! }
  @@queues = {}
end

.get_queue(queue_name) ⇒ Object



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

def get_queue(queue_name)
  @@queues[queue_name] ||= Sparrow::Queues::Memory.new(queue_name)
end

.get_stats(queue_name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sparrow/queue.rb', line 37

def get_stats(queue_name)
  stats = {
    :type =>              'memory',
    :total_bytes =>       (File.size?(Sparrow.base_dir) || 0),
    :queues  =>           Dir.glob(File.join(Sparrow.base_dir, '*')).collect {|s| File.basename(s) }.join(','),
    :number_of_queues =>  queues.keys.length,
    :debug =>             Sparrow.options[:debug],
    :pid =>               Process.pid,
    :uptime =>            Time.now - Sparrow.options[:start_time],
    :time =>              Time.now.to_i,
    :version =>           Sparrow::VERSION,
    :rusage_user =>       Process.times.utime,
    :rusage_system =>     Process.times.stime
  }
  if queue_name
    queue = get_queue(queue_name)
    stats.merge!({
      :total_items =>     queue.count_push, 
      :curr_items =>      queue.count
    })
  end
  stats
end

.next_message(queue_name) ⇒ Object



13
14
15
# File 'lib/sparrow/queue.rb', line 13

def next_message(queue_name)
  self.get_queue(queue_name).pop
end

.shutdown!Object



33
34
35
# File 'lib/sparrow/queue.rb', line 33

def shutdown!
  @@queues.each {|name, q| q.shutdown! }
end