iron_mq 4.0.1 → 4.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae70cddc4f116d5a8d516a5eed1cd722f221df59
4
- data.tar.gz: ba911a0556103b6fa9c4b5407b59fd6966b92661
3
+ metadata.gz: 60ddd32d17b9bf5b091151e1e26915b75a60bb05
4
+ data.tar.gz: f21165a64e0001ecfff3e9c2144cec2b0cc9c9d2
5
5
  SHA512:
6
- metadata.gz: 8e07437588ae4af6e20c4816d23db5a88aed43e39311c329a3871751c96147628bf984044d333f270c5b55a8e67af17922fc7bf5694550198cae89fd5f3fea19
7
- data.tar.gz: c4a9adda56a141bcad44756ae830310503410019725aa5590d1b36f9aa9449b21ed0ed03db725ad83e8842ba3360c5e6d1d9de3d96aa2b883f150a4335765c7a
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.1)
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.2.0)
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)
@@ -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
- response.each_with_object([]) { |q_info, ret| ret << Queue.new(self, q_info["name"]) }
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
@@ -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'].each_with_object([]) do |subscriber, ret|
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
- begin
32
- call_api_and_parse_response(:delete)
33
- rescue Rest::HttpError => ex
34
- if ex.code == 404
35
- Rest.logger.info("Delete got 404, safe to ignore.")
36
- else
37
- raise ex
38
- end
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
 
@@ -12,14 +12,15 @@ module IronMQ
12
12
  end
13
13
 
14
14
  def info
15
- info = raw
16
- begin
17
- # Do not instantiate response
18
- info = call_api_and_parse_response(:get, '', {}, false)
19
- rescue Rest::HttpError
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.each_with_object([]) do |msg, res|
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.each_with_object([]) do |msg, res|
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| {'id' => 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"].each_with_object([]) do |id, responses|
124
- # responses << ResponseBase.new({"id" => id, "msg" => res["msg"]})
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
- res = info.send(meth)
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
- if multiple
211
- messages.each_with_object([]) do |m, msgs|
212
- msgs << Message.new(self, m)
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
@@ -22,7 +22,9 @@ module IronMQ
22
22
  private
23
23
 
24
24
  def stringify_keys(hash)
25
- hash.keys.each_with_object({}) { |k, res| res[k.to_s] = hash[k] }
25
+ hash.keys.each { |k| hash[k.to_s] = hash.delete(k) }
26
+
27
+ hash
26
28
  end
27
29
  end
28
30
 
@@ -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
@@ -1,4 +1,4 @@
1
1
  module IronMQ
2
- VERSION = "4.0.1"
2
+ VERSION = "4.0.3"
3
3
  end
4
4
 
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 0.5
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.raw['timeout'], 30
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 0.5
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.raw['timeout'], 30
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 0.5
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 new_msg.id, msg.id
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? == true
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 0.5 # make sure the counter has time to update
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 0.5
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.1
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-20 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_core