Class: BugsBunny::Queue
- Inherits:
-
Object
show all
- Includes:
- Helper
- Defined in:
- lib/bugs_bunny/queue.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helper
#print_queue, #print_table, #read_dump
Constructor Details
#initialize(*params) ⇒ Queue
Returns a new instance of Queue.
22
23
24
25
26
27
28
|
# File 'lib/bugs_bunny/queue.rb', line 22
def initialize(*params)
@name, d, a, args, @ready, @noack, @commit, @msgs,
@users, @acts, @memory = *params
@durable = eval(d) if d @auto_delete = eval(a) if a @mq = MQ.queue(@name, :passive => true)
end
|
Instance Attribute Details
#acts ⇒ Object
Returns the value of attribute acts.
4
5
6
|
# File 'lib/bugs_bunny/queue.rb', line 4
def acts
@acts
end
|
#commit ⇒ Object
Returns the value of attribute commit.
4
5
6
|
# File 'lib/bugs_bunny/queue.rb', line 4
def commit
@commit
end
|
#msgs ⇒ Object
Returns the value of attribute msgs.
4
5
6
|
# File 'lib/bugs_bunny/queue.rb', line 4
def msgs
@msgs
end
|
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'lib/bugs_bunny/queue.rb', line 4
def name
@name
end
|
#noack ⇒ Object
Returns the value of attribute noack.
4
5
6
|
# File 'lib/bugs_bunny/queue.rb', line 4
def noack
@noack
end
|
#ready ⇒ Object
Returns the value of attribute ready.
4
5
6
|
# File 'lib/bugs_bunny/queue.rb', line 4
def ready
@ready
end
|
#users ⇒ Object
Returns the value of attribute users.
4
5
6
|
# File 'lib/bugs_bunny/queue.rb', line 4
def users
@users
end
|
Class Method Details
.all ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/bugs_bunny/queue.rb', line 7
def self.all
`rabbitmqctl list_queues -p #{Opt[:rabbit][:vhost]} name durable auto_delete arguments messages_ready messages_unacknowledged messages_uncommitted messages consumers transactions memory`.split("\n").each do |l|
next if l =~ /Listing|\.\./
@queues << BugsBunny::Queue.new(*l.split("\t"))
end
@queues
end
|
.create(name) ⇒ Object
16
17
18
19
20
|
# File 'lib/bugs_bunny/queue.rb', line 16
def self.create(name)
MQ.queue(name, :durable => true).status do |msg, users|
puts "#{msg} messages, #{users} consumers."
end
end
|
Instance Method Details
#<=>(other) ⇒ Object
89
90
91
|
# File 'lib/bugs_bunny/queue.rb', line 89
def <=>(other)
@name <=> other.name
end
|
#add(txt) ⇒ Object
Also known as:
publish
58
59
60
61
|
# File 'lib/bugs_bunny/queue.rb', line 58
def add(txt)
@mq.publish(txt)
halt
end
|
#delete ⇒ Object
80
81
82
83
|
# File 'lib/bugs_bunny/queue.rb', line 80
def delete
@mq.delete halt
end
|
#info ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/bugs_bunny/queue.rb', line 30
def info
puts "About #{@name}"
@mq.status do |msg, users|
puts "#{msg} messages, #{users} consumers."
end
halt
end
|
#inspect ⇒ Object
Also known as:
live, watch
47
48
49
50
51
52
53
54
|
# File 'lib/bugs_bunny/queue.rb', line 47
def inspect
@mq.subscribe(:ack => true) do |h, body| print_queue(h, body)
end
end
|
#list ⇒ Object
38
39
40
41
|
# File 'lib/bugs_bunny/queue.rb', line 38
def list
inspect
EM.add_timer(1) { halt }
end
|
#memory ⇒ Object
43
44
45
|
# File 'lib/bugs_bunny/queue.rb', line 43
def memory
@memory end
|
#pop ⇒ Object
Also known as:
get
64
65
66
67
68
69
|
# File 'lib/bugs_bunny/queue.rb', line 64
def pop
@mq.pop do |h, b|
print_queue(h, b) if b
halt
end
end
|
#purge ⇒ Object
Also known as:
clean
72
73
74
75
76
77
|
# File 'lib/bugs_bunny/queue.rb', line 72
def purge
print "Purging #{name}... "
@mq.purge
print "Done.\n"
halt
end
|
#to_s ⇒ Object
85
86
87
|
# File 'lib/bugs_bunny/queue.rb', line 85
def to_s
"#{@name} #{kind}: #{@msgs} messages"
end
|