Class: IronMQ::Queue
- Inherits:
-
Object
- Object
- IronMQ::Queue
- Defined in:
- lib/iron_mq/queues.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #delete(id, options = {}) ⇒ Object
- #delete_queue ⇒ Object
- #get(options = {}) ⇒ Object
- #id ⇒ Object
-
#initialize(client, res) ⇒ Queue
constructor
A new instance of Queue.
-
#load_queue ⇒ Object
Used if lazy loading.
- #name ⇒ Object
-
#poll(options = {}, &blk) ⇒ Object
This will continuously poll for a message and pass it to the block.
- #post(body, options = {}) ⇒ Object
- #raw ⇒ Object
- #reload ⇒ Object
- #size ⇒ Object
- #total_messages ⇒ Object
Constructor Details
#initialize(client, res) ⇒ Queue
Returns a new instance of Queue.
72 73 74 75 |
# File 'lib/iron_mq/queues.rb', line 72 def initialize(client, res) @client = client @data = res end |
Instance Method Details
#[](key) ⇒ Object
81 82 83 |
# File 'lib/iron_mq/queues.rb', line 81 def [](key) raw[key] end |
#clear ⇒ Object
105 106 107 |
# File 'lib/iron_mq/queues.rb', line 105 def clear() @client.queues.clear(:name => name) end |
#delete(id, options = {}) ⇒ Object
162 163 164 |
# File 'lib/iron_mq/queues.rb', line 162 def delete(id, ={}) @client..delete(id, .merge(:queue_name => name)) end |
#delete_queue ⇒ Object
109 110 111 |
# File 'lib/iron_mq/queues.rb', line 109 def delete_queue() @client.queues.delete(:name=>name) end |
#get(options = {}) ⇒ Object
133 134 135 |
# File 'lib/iron_mq/queues.rb', line 133 def get(={}) @client..get(.merge(:queue_name => name)) end |
#id ⇒ Object
85 86 87 |
# File 'lib/iron_mq/queues.rb', line 85 def id raw["id"] end |
#load_queue ⇒ Object
Used if lazy loading
98 99 100 101 102 103 |
# File 'lib/iron_mq/queues.rb', line 98 def load_queue q = @client.queues.get(:name => name) @client.logger.debug "GOT Q: " + q.inspect @data = q.raw q end |
#name ⇒ Object
89 90 91 |
# File 'lib/iron_mq/queues.rb', line 89 def name raw["name"] end |
#poll(options = {}, &blk) ⇒ Object
This will continuously poll for a message and pass it to the block. For example:
queue.poll { |msg| puts msg.body }
options:
-
:sleep_duration=>seconds => time between polls if msg is nil. default 1.
-
:break_if_nil=>true/false => if true, will break if msg is nil (ie: queue is empty)
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/iron_mq/queues.rb', line 144 def poll(={}, &blk) sleep_duration = [:sleep_duration] || 1 while true #p options msg = get() if msg.nil? if [:break_if_nil] break else sleep sleep_duration end else yield msg msg.delete end end end |
#post(body, options = {}) ⇒ Object
129 130 131 |
# File 'lib/iron_mq/queues.rb', line 129 def post(body, ={}) @client..post(body, .merge(:queue_name => name)) end |
#raw ⇒ Object
77 78 79 |
# File 'lib/iron_mq/queues.rb', line 77 def raw @data end |
#reload ⇒ Object
93 94 95 |
# File 'lib/iron_mq/queues.rb', line 93 def reload load_queue end |
#size ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/iron_mq/queues.rb', line 113 def size return raw["size"] if raw["size"] return @size if @size q = load_queue() @size = q.size @size end |
#total_messages ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/iron_mq/queues.rb', line 121 def return raw["total_messages"] if raw["total_messages"] return @total_messages if @total_messages q = load_queue() @total_messages = q. @total_messages end |