iron_mq 4.0.1 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +1 -0
- data/lib/iron_mq/client.rb +7 -1
- data/lib/iron_mq/messages.rb +9 -11
- data/lib/iron_mq/queues.rb +25 -26
- data/lib/iron_mq/response.rb +3 -1
- data/lib/iron_mq/subscribers.rb +8 -0
- data/lib/iron_mq/version.rb +1 -1
- data/lib/iron_mq.rb +1 -0
- data/test/test_base.rb +3 -3
- data/test/test_iron_mq.rb +18 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ddd32d17b9bf5b091151e1e26915b75a60bb05
|
4
|
+
data.tar.gz: f21165a64e0001ecfff3e9c2144cec2b0cc9c9d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d96d56ac39de492bc36e976b8467101bac942c34cf34af3896dc959d5f732b755d784060671e3ab25b7bd68dfd3a077c185e14fab7c4dd80e708fcff8f55611b
|
7
|
+
data.tar.gz: 0dbc4b37f6344681aec4d18b08fd2148738accd8f0abc0c6965ded1325f074e78d56d466d1035f3df8e7fe7189078cb5b076e79796438040a5c4daebc8466c93
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iron_mq (4.0.
|
4
|
+
iron_mq (4.0.3)
|
5
5
|
iron_core (>= 0.5.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -20,9 +20,9 @@ GEM
|
|
20
20
|
net-http-persistent (2.8)
|
21
21
|
quicky (0.4.0)
|
22
22
|
rake (10.0.3)
|
23
|
-
rest (2.
|
24
|
-
net-http-persistent
|
23
|
+
rest (2.5.0)
|
25
24
|
rest-client (>= 0.3.0)
|
25
|
+
typhoeus (>= 0.5.4)
|
26
26
|
rest-client (1.6.7)
|
27
27
|
mime-types (>= 1.16)
|
28
28
|
test-unit (2.5.4)
|
data/README.md
CHANGED
@@ -116,6 +116,7 @@ all_queues = ironmq.queues.all # => [#<IronMQ::Queue:...>, ...]
|
|
116
116
|
|
117
117
|
* `page`: The 0-based page to view. The default is 0.
|
118
118
|
* `per_page`: The number of queues to return per page. The default is 30, the maximum is 100.
|
119
|
+
* `raw`: Set it to true to obtain data in raw format. The default is false.
|
119
120
|
|
120
121
|
```ruby
|
121
122
|
queues = ironmq.queues.all(:page => 1, :per_page => 10)
|
data/lib/iron_mq/client.rb
CHANGED
@@ -37,9 +37,15 @@ module IronMQ
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def queues_list(options = {})
|
40
|
+
is_raw = [options.delete(:raw),
|
41
|
+
options.delete('raw')].compact.first
|
40
42
|
response = parse_response(get('', options)) # GET base_url
|
41
43
|
# returns list of evaluated queues
|
42
|
-
|
44
|
+
if is_raw
|
45
|
+
response.map{ |q_info| ResponseBase.new(q_info) }
|
46
|
+
else
|
47
|
+
response.map{ |q_info| Queue.new(self, q_info["name"]) }
|
48
|
+
end
|
43
49
|
end
|
44
50
|
|
45
51
|
alias_method :list, :queues_list
|
data/lib/iron_mq/messages.rb
CHANGED
@@ -22,20 +22,18 @@ module IronMQ
|
|
22
22
|
def subscribers(options = {})
|
23
23
|
response = call_api_and_parse_response(:get, "/subscribers", {}, false)
|
24
24
|
|
25
|
-
response['subscribers'].
|
26
|
-
ret << Subscriber.new(subscriber, self, options)
|
27
|
-
end
|
25
|
+
response['subscribers'].map { |s| Subscriber.new(s, self, options) }
|
28
26
|
end
|
29
27
|
|
30
28
|
def delete
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
call_api_and_parse_response(:delete)
|
30
|
+
rescue Rest::HttpError => ex
|
31
|
+
if ex.code == 404
|
32
|
+
Rest.logger.info("Delete got 404, safe to ignore.")
|
33
|
+
# return ResponseBase as normal
|
34
|
+
ResponseBase.new({"msg" => "Deleted"})
|
35
|
+
else
|
36
|
+
raise ex
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
data/lib/iron_mq/queues.rb
CHANGED
@@ -12,14 +12,15 @@ module IronMQ
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def info
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
info
|
19
|
-
|
15
|
+
call_api_and_parse_response(:get)
|
16
|
+
rescue Rest::HttpError => ex
|
17
|
+
if ex.code == 404
|
18
|
+
Rest.logger.info("GET Queue#info return 404, treat as new queue, safe to ignore.")
|
19
|
+
# return ResponseBase as normal
|
20
|
+
ResponseBase.new(raw)
|
21
|
+
else
|
22
|
+
raise ex
|
20
23
|
end
|
21
|
-
|
22
|
-
ResponseBase.new(info)
|
23
24
|
end
|
24
25
|
|
25
26
|
def size
|
@@ -56,6 +57,14 @@ module IronMQ
|
|
56
57
|
# Backward compatibility, better name is `delete`
|
57
58
|
def delete_queue
|
58
59
|
call_api_and_parse_response(:delete)
|
60
|
+
rescue Rest::HttpError => ex
|
61
|
+
if ex.code == 404
|
62
|
+
Rest.logger.info("Delete got 404, safe to ignore.")
|
63
|
+
# return ResponseBase as normal
|
64
|
+
ResponseBase.new({"msg" => "Deleted"})
|
65
|
+
else
|
66
|
+
raise ex
|
67
|
+
end
|
59
68
|
end
|
60
69
|
|
61
70
|
# Backward compatibility
|
@@ -96,14 +105,10 @@ module IronMQ
|
|
96
105
|
batch = true
|
97
106
|
# FIXME: This maybe better to process Array of Objects the same way as for single message.
|
98
107
|
#
|
99
|
-
# payload.
|
100
|
-
# res << options.merge(:body => msg)
|
101
|
-
# end
|
108
|
+
# payload.map { |msg| options.merge(:body => msg) }
|
102
109
|
#
|
103
110
|
# For now user must pass objects like `[{:body => msg1}, {:body => msg2}]`
|
104
|
-
payload.
|
105
|
-
res << msg.merge(options)
|
106
|
-
end
|
111
|
+
payload.map { |msg| msg.merge(options) }
|
107
112
|
else
|
108
113
|
[ options.merge(:body => payload) ]
|
109
114
|
end
|
@@ -113,16 +118,15 @@ module IronMQ
|
|
113
118
|
|
114
119
|
if instantiate
|
115
120
|
n = batch ? 2 : 1
|
116
|
-
msg_ids = res["ids"].map { |id| {
|
121
|
+
msg_ids = res["ids"].map { |id| {"id" => id} }
|
117
122
|
|
118
123
|
process_messages(msg_ids, {:n => n})
|
119
124
|
else
|
120
125
|
if batch
|
121
126
|
# FIXME: Return Array of ResponsBase instead, it seems more clear than raw response
|
122
127
|
#
|
123
|
-
# res["ids"].
|
124
|
-
#
|
125
|
-
# end
|
128
|
+
# res["ids"].map { |id| ResponseBase.new({"id" => id, "msg" => res["msg"]}) }
|
129
|
+
#
|
126
130
|
ResponseBase.new(res) # Backward capable
|
127
131
|
else
|
128
132
|
ResponseBase.new({"id" => res["ids"][0], "msg" => res["msg"]})
|
@@ -190,8 +194,7 @@ module IronMQ
|
|
190
194
|
# queue.size
|
191
195
|
# etc.
|
192
196
|
if args.length == 0
|
193
|
-
|
194
|
-
res ? res : super
|
197
|
+
self.info[meth.to_s]
|
195
198
|
else
|
196
199
|
super
|
197
200
|
end
|
@@ -207,13 +210,9 @@ module IronMQ
|
|
207
210
|
multiple = wait_for_multiple?(options)
|
208
211
|
|
209
212
|
if messages.is_a?(Array) && messages.size > 0
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
end
|
214
|
-
else
|
215
|
-
Message.new(self, messages[0])
|
216
|
-
end
|
213
|
+
msgs = messages.map { |m| Message.new(self, m) }
|
214
|
+
|
215
|
+
multiple ? msgs : msgs[0]
|
217
216
|
else
|
218
217
|
multiple ? [] : nil
|
219
218
|
end
|
data/lib/iron_mq/response.rb
CHANGED
data/lib/iron_mq/subscribers.rb
CHANGED
@@ -13,6 +13,14 @@ module IronMQ
|
|
13
13
|
# `options` was kept for backward compatibility
|
14
14
|
def delete(options = {})
|
15
15
|
@message.call_api_and_parse_response(:delete, path)
|
16
|
+
rescue Rest::HttpError => ex
|
17
|
+
if ex.code == 404
|
18
|
+
Rest.logger.info("Delete got 404, safe to ignore.")
|
19
|
+
# return ResponseBase as normal
|
20
|
+
ResponseBase.new({"msg" => "Deleted"})
|
21
|
+
else
|
22
|
+
raise ex
|
23
|
+
end
|
16
24
|
end
|
17
25
|
|
18
26
|
alias_method :acknowledge, :delete
|
data/lib/iron_mq/version.rb
CHANGED
data/lib/iron_mq.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path('iron_mq/response', File.dirname(__FILE__))
|
2
|
+
require File.expand_path('iron_mq/subscribers', File.dirname(__FILE__))
|
2
3
|
require File.expand_path('iron_mq/queues', File.dirname(__FILE__))
|
3
4
|
require File.expand_path('iron_mq/messages', File.dirname(__FILE__))
|
4
5
|
require File.expand_path('iron_mq/client', File.dirname(__FILE__))
|
data/test/test_base.rb
CHANGED
@@ -32,9 +32,9 @@ class TestBase < Test::Unit::TestCase
|
|
32
32
|
@host = "#{config['host'] || "mq-aws-us-east-1.iron.io"}"
|
33
33
|
|
34
34
|
@client = IronMQ::Client.new(@config['iron'])
|
35
|
-
|
36
|
-
Rest.logger.level = Logger::DEBUG # this doesn't work for some reason?
|
37
|
-
IronCore::Logger.logger.level = Logger::DEBUG
|
35
|
+
puts "IronMQ::VERSION = #{IronMQ::VERSION}"
|
36
|
+
#Rest.logger.level = Logger::DEBUG # this doesn't work for some reason?
|
37
|
+
#IronCore::Logger.logger.level = Logger::DEBUG
|
38
38
|
|
39
39
|
@queue_name = 'ironmq-ruby-tests' # default queue for tests
|
40
40
|
end
|
data/test/test_iron_mq.rb
CHANGED
@@ -159,9 +159,8 @@ class IronMQTests < TestBase
|
|
159
159
|
|
160
160
|
tries = MAX_TRIES
|
161
161
|
while tries > 0
|
162
|
-
sleep
|
162
|
+
sleep 2
|
163
163
|
tries -= 1
|
164
|
-
sleep 1
|
165
164
|
|
166
165
|
new_msg = queue.get
|
167
166
|
# p new_msg
|
@@ -180,7 +179,7 @@ class IronMQTests < TestBase
|
|
180
179
|
msg = queue.get
|
181
180
|
# p msg
|
182
181
|
assert msg
|
183
|
-
assert_equal msg.
|
182
|
+
assert_equal 30, msg.timeout
|
184
183
|
|
185
184
|
msg_nil = queue.get
|
186
185
|
# p msg_nil
|
@@ -188,9 +187,8 @@ class IronMQTests < TestBase
|
|
188
187
|
|
189
188
|
tries = MAX_TRIES
|
190
189
|
while tries > 0
|
191
|
-
sleep
|
190
|
+
sleep 2
|
192
191
|
tries -= 1
|
193
|
-
sleep 1
|
194
192
|
|
195
193
|
new_msg = queue.get
|
196
194
|
next if new_msg.nil?
|
@@ -205,8 +203,9 @@ class IronMQTests < TestBase
|
|
205
203
|
# timeout on get
|
206
204
|
res = queue.post("hello world timeout3!")
|
207
205
|
msg = queue.get(:timeout => 30)
|
206
|
+
puts "MESSAGE IS #{msg.inspect}"
|
208
207
|
assert msg
|
209
|
-
assert_equal msg.
|
208
|
+
assert_equal msg.timeout, 30
|
210
209
|
|
211
210
|
msg_nil = queue.get
|
212
211
|
# p msg_nil
|
@@ -214,14 +213,13 @@ class IronMQTests < TestBase
|
|
214
213
|
|
215
214
|
tries = MAX_TRIES
|
216
215
|
while tries > 0
|
217
|
-
sleep
|
216
|
+
sleep 2
|
218
217
|
tries -= 1
|
219
|
-
sleep 1
|
220
218
|
|
221
219
|
new_msg = queue.get
|
222
220
|
next if new_msg.nil?
|
223
221
|
|
224
|
-
assert_equal
|
222
|
+
assert_equal msg.id, new_msg.id
|
225
223
|
|
226
224
|
new_msg.delete
|
227
225
|
break
|
@@ -245,7 +243,11 @@ class IronMQTests < TestBase
|
|
245
243
|
# q = @client.queues.get(:name => "some_queue_that_does_not_exist")
|
246
244
|
#end
|
247
245
|
queue = @client.queues.get(:name => "some_queue_that_does_not_exist")
|
248
|
-
assert queue.new?
|
246
|
+
assert queue.new?
|
247
|
+
|
248
|
+
# create at least one queue
|
249
|
+
queue.post('create queue message')
|
250
|
+
assert_equal queue.new?, false, "queue must exist on the service after post message to"
|
249
251
|
|
250
252
|
res = @client.queues.list
|
251
253
|
# puts "res.size: #{res.size}"
|
@@ -261,6 +263,10 @@ class IronMQTests < TestBase
|
|
261
263
|
# res.each do |q| { p q.name }
|
262
264
|
|
263
265
|
assert_equal 0, res.size
|
266
|
+
|
267
|
+
# delete queue on test complete
|
268
|
+
resp = queue.delete_queue
|
269
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
264
270
|
end
|
265
271
|
|
266
272
|
def test_delay
|
@@ -544,7 +550,7 @@ class IronMQTests < TestBase
|
|
544
550
|
val = "hi mr clean"
|
545
551
|
queue.post(val)
|
546
552
|
|
547
|
-
sleep
|
553
|
+
sleep 2 # make sure the counter has time to update
|
548
554
|
assert_equal 1, queue.size
|
549
555
|
|
550
556
|
queue.clear
|
@@ -581,7 +587,7 @@ class IronMQTests < TestBase
|
|
581
587
|
while tries > 0
|
582
588
|
tries -= 1
|
583
589
|
break if 0 == queue.size
|
584
|
-
sleep
|
590
|
+
sleep 1
|
585
591
|
end
|
586
592
|
assert_not_equal tries, 0
|
587
593
|
|
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: 4.0.
|
4
|
+
version: 4.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Yantsevich
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: iron_core
|