iron_mq 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/README.md +4 -5
- data/lib/iron_mq/queues.rb +29 -5
- data/lib/iron_mq/version.rb +1 -1
- data/test/test_iron_mq.rb +44 -4
- data/test/tmp.rb +0 -21
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,13 +4,13 @@ IronMQ Ruby Client
|
|
4
4
|
Getting Started
|
5
5
|
==============
|
6
6
|
|
7
|
-
1
|
7
|
+
1\. Install the gem:
|
8
8
|
|
9
9
|
gem install iron_mq
|
10
10
|
|
11
|
-
2
|
11
|
+
2\. Setup your Iron.io credentials: http://dev.iron.io/articles/configuration/
|
12
12
|
|
13
|
-
3
|
13
|
+
3\. Create an IronMQ client object:
|
14
14
|
|
15
15
|
@ironmq = IronMQ::Client.new()
|
16
16
|
|
@@ -28,8 +28,7 @@ Now you can use it:
|
|
28
28
|
|
29
29
|
**Push** a message on the queue:
|
30
30
|
|
31
|
-
|
32
|
-
p msg
|
31
|
+
@queue.post("hello world!")
|
33
32
|
|
34
33
|
**Pop** a message off the queue:
|
35
34
|
|
data/lib/iron_mq/queues.rb
CHANGED
@@ -87,14 +87,14 @@ module IronMQ
|
|
87
87
|
|
88
88
|
# Used if lazy loading
|
89
89
|
def load_queue
|
90
|
-
q = @client.queues.get(:name=>name)
|
90
|
+
q = @client.queues.get(:name => name)
|
91
91
|
@client.logger.debug "GOT Q: " + q.inspect
|
92
92
|
@data = q.raw
|
93
93
|
q
|
94
94
|
end
|
95
95
|
|
96
96
|
def clear()
|
97
|
-
@client.queues.clear(:name=>name)
|
97
|
+
@client.queues.clear(:name => name)
|
98
98
|
end
|
99
99
|
|
100
100
|
def size
|
@@ -114,15 +114,39 @@ module IronMQ
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def post(body, options={})
|
117
|
-
@client.messages.post(body, options.merge(:queue_name=>name))
|
117
|
+
@client.messages.post(body, options.merge(:queue_name => name))
|
118
118
|
end
|
119
119
|
|
120
120
|
def get(options={})
|
121
|
-
@client.messages.get(options.merge(:queue_name=>name))
|
121
|
+
@client.messages.get(options.merge(:queue_name => name))
|
122
|
+
end
|
123
|
+
|
124
|
+
# This will continuously poll for a message and pass it to the block. For example:
|
125
|
+
#
|
126
|
+
# queue.poll { |msg| puts msg.body }
|
127
|
+
#
|
128
|
+
# options:
|
129
|
+
# - :sleep_duration=>seconds => time between polls if msg is nil. default 1.
|
130
|
+
# - :break_on_nil=>true/false => if true, will break if msg is nil (ie: queue is empty)
|
131
|
+
def poll(options={}, &blk)
|
132
|
+
sleep_duration = options[:sleep_duration] || 1
|
133
|
+
while true
|
134
|
+
p options
|
135
|
+
msg = get(options)
|
136
|
+
if msg.nil?
|
137
|
+
if options[:break_if_nil]
|
138
|
+
break
|
139
|
+
else
|
140
|
+
sleep sleep_duration
|
141
|
+
end
|
142
|
+
end
|
143
|
+
yield msg
|
144
|
+
msg.delete
|
145
|
+
end
|
122
146
|
end
|
123
147
|
|
124
148
|
def delete(id, options={})
|
125
|
-
@client.messages.delete(id, options.merge(:queue_name=>name))
|
149
|
+
@client.messages.delete(id, options.merge(:queue_name => name))
|
126
150
|
end
|
127
151
|
|
128
152
|
end
|
data/lib/iron_mq/version.rb
CHANGED
data/test/test_iron_mq.rb
CHANGED
@@ -17,11 +17,11 @@ class IronMQTests < TestBase
|
|
17
17
|
clear_queue()
|
18
18
|
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def test_performance_post_100_messages
|
22
22
|
@client.queue_name = 'test_basics3'
|
23
23
|
# slower to rackspace since this is running on aws
|
24
|
-
timeout = @client.host.include?('rackspace') ? 40 :
|
24
|
+
timeout = @client.host.include?('rackspace') ? 40 : 12
|
25
25
|
assert_performance timeout do
|
26
26
|
100.times do
|
27
27
|
@client.messages.post("hello world!")
|
@@ -74,7 +74,6 @@ class IronMQTests < TestBase
|
|
74
74
|
assert res.nil?
|
75
75
|
|
76
76
|
|
77
|
-
|
78
77
|
# new style of referencing queue
|
79
78
|
queue = @client.queue("test_basics3")
|
80
79
|
v = "hello big world"
|
@@ -269,7 +268,7 @@ class IronMQTests < TestBase
|
|
269
268
|
assert msgr.nil?
|
270
269
|
|
271
270
|
# let's release it in 10 seconds
|
272
|
-
@client.messages.release(msg_id, :delay=>10)
|
271
|
+
@client.messages.release(msg_id, :delay => 10)
|
273
272
|
msg = @client.messages.get
|
274
273
|
p msg
|
275
274
|
assert msg.nil?
|
@@ -293,6 +292,47 @@ class IronMQTests < TestBase
|
|
293
292
|
|
294
293
|
end
|
295
294
|
|
295
|
+
def test_clear
|
296
|
+
|
297
|
+
q = @client.queue("clearer")
|
298
|
+
|
299
|
+
clear_queue(q.name)
|
300
|
+
|
301
|
+
val = "hi mr clean"
|
302
|
+
q.post(val)
|
303
|
+
assert q.size == 1
|
304
|
+
|
305
|
+
q.clear
|
306
|
+
msg = q.get
|
307
|
+
assert msg.nil?
|
308
|
+
|
309
|
+
q.reload
|
310
|
+
|
311
|
+
assert q.size == 0
|
312
|
+
|
313
|
+
end
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
def test_poll
|
318
|
+
queue = @client.queue("test_poll")
|
319
|
+
queue.clear
|
320
|
+
|
321
|
+
v = "hello world"
|
322
|
+
5.times do
|
323
|
+
queue.post(v)
|
324
|
+
end
|
325
|
+
|
326
|
+
i = 0
|
327
|
+
queue.poll(:break_if_nil=>true) do |msg|
|
328
|
+
assert msg.body.include?("hello")
|
329
|
+
i += 1
|
330
|
+
end
|
331
|
+
assert i == 5
|
332
|
+
|
333
|
+
assert queue.reload.size == 0
|
334
|
+
|
335
|
+
end
|
296
336
|
|
297
337
|
|
298
338
|
end
|
data/test/tmp.rb
CHANGED
@@ -13,25 +13,4 @@ class IronMQTests < TestBase
|
|
13
13
|
|
14
14
|
end
|
15
15
|
|
16
|
-
def test_clear
|
17
|
-
|
18
|
-
q = @client.queue("clearer")
|
19
|
-
|
20
|
-
clear_queue(q.name)
|
21
|
-
|
22
|
-
val = "hi mr clean"
|
23
|
-
q.post(val)
|
24
|
-
assert q.size == 1
|
25
|
-
|
26
|
-
q.clear
|
27
|
-
msg = q.get
|
28
|
-
assert msg.nil?
|
29
|
-
|
30
|
-
q.reload
|
31
|
-
|
32
|
-
assert q.size == 0
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron_mq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: iron_core
|