iron_mq 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iron_mq (2.1.0)
5
- iron_core (>= 0.2.0)
4
+ iron_mq (2.1.2)
5
+ iron_core (>= 0.4.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -11,11 +11,11 @@ GEM
11
11
  concur (1.0.0)
12
12
  faraday
13
13
  faraday
14
- faraday (0.8.1)
14
+ faraday (0.8.4)
15
15
  multipart-post (~> 1.1)
16
- ffi (1.1.3)
17
- iron_core (0.3.3)
18
- rest (>= 2.0.0)
16
+ ffi (1.1.5)
17
+ iron_core (0.4.2)
18
+ rest (>= 2.0.2)
19
19
  mime-types (1.19)
20
20
  multipart-post (1.1.5)
21
21
  net-http-persistent (2.7)
data/README.md CHANGED
@@ -33,15 +33,20 @@ Now you can use it:
33
33
  **Pop** a message off the queue:
34
34
 
35
35
  msg = @queue.get()
36
- p msg
36
+ puts msg.body
37
+
38
+ **Poll** for messages:
39
+
40
+ @queue.poll do |msg|
41
+ puts msg.body
42
+ end
37
43
 
38
44
  When you pop/get a message from the queue, it will NOT be deleted. It will eventually go back onto the queue after
39
45
  a timeout if you don't delete it (default timeout is 10 minutes).
40
46
 
41
47
  **Delete** a message from the queue:
42
48
 
43
- res = msg.delete # or @queue.delete(msg.id)
44
- p res
49
+ msg.delete # or @queue.delete(msg.id)
45
50
 
46
51
  Delete a message from the queue when you're done with it.
47
52
 
data/iron_mq.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.required_rubygems_version = ">= 1.3.6"
18
18
  gem.required_ruby_version = Gem::Requirement.new(">= 1.9")
19
- gem.add_runtime_dependency "iron_core", ">= 0.2.0"
19
+ gem.add_runtime_dependency "iron_core", ">= 0.4.2"
20
20
 
21
21
  gem.add_development_dependency "test-unit"
22
22
  gem.add_development_dependency "rake"
@@ -11,12 +11,12 @@ module IronMQ
11
11
 
12
12
  def initialize(options={})
13
13
  default_options = {
14
- :scheme => 'https',
15
- :host => IronMQ::Client::AWS_US_EAST_HOST,
16
- :port => 443,
17
- :api_version => 1,
18
- :user_agent => 'iron_mq_ruby-' + IronMQ::VERSION + ' (iron_core_ruby-' + IronCore.version + ')',
19
- :queue_name => 'default'
14
+ :scheme => 'https',
15
+ :host => IronMQ::Client::AWS_US_EAST_HOST,
16
+ :port => 443,
17
+ :api_version => 1,
18
+ :user_agent => 'iron_mq_ruby-' + IronMQ::VERSION + ' (iron_core_ruby-' + IronCore.version + ')',
19
+ :queue_name => 'default'
20
20
  }
21
21
 
22
22
  super('iron', 'mq', options, default_options, [:project_id, :token, :api_version, :queue_name])
@@ -33,15 +33,14 @@ module IronMQ
33
33
  super.merge({'Authorization' => "OAuth #{@token}"})
34
34
  end
35
35
 
36
- def url
36
+ def base_url
37
37
  super + @api_version.to_s + '/'
38
38
  end
39
39
 
40
40
  def queue(name)
41
- return Queue.new(self, {"name"=>name})
41
+ return Queue.new(self, {"name" => name})
42
42
  end
43
43
 
44
-
45
44
  def messages
46
45
  return Messages.new(self)
47
46
  end
@@ -10,7 +10,7 @@ module IronMQ
10
10
  def path(options={})
11
11
  path = "projects/#{@client.project_id}/queues"
12
12
  if options[:name]
13
- path << "/#{URI.escape(options[:name])}"
13
+ path << "/#{CGI::escape(options[:name])}"
14
14
  end
15
15
  path
16
16
  end
@@ -31,7 +31,14 @@ module IronMQ
31
31
  def clear(options={})
32
32
  @client.logger.debug "Clearing queue #{options[:name]}"
33
33
  r1 = @client.post("#{path(options)}/clear", options)
34
- p r1
34
+ @client.logger.debug "Clear result: #{r1}"
35
+ r1
36
+ end
37
+
38
+ def delete(options={})
39
+ @client.logger.debug "Deleting queue #{options[:name]}"
40
+ r1 = @client.delete("#{path(options)}", options)
41
+ @client.logger.debug "Delete result: #{r1}"
35
42
  r1
36
43
  end
37
44
 
@@ -97,6 +104,10 @@ module IronMQ
97
104
  @client.queues.clear(:name => name)
98
105
  end
99
106
 
107
+ def delete_queue()
108
+ @client.queues.delete(:name=>name)
109
+ end
110
+
100
111
  def size
101
112
  return raw["size"] if raw["size"]
102
113
  return @size if @size
@@ -127,7 +138,7 @@ module IronMQ
127
138
  #
128
139
  # options:
129
140
  # - :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)
141
+ # - :break_if_nil=>true/false => if true, will break if msg is nil (ie: queue is empty)
131
142
  def poll(options={}, &blk)
132
143
  sleep_duration = options[:sleep_duration] || 1
133
144
  while true
@@ -1,3 +1,3 @@
1
1
  module IronMQ
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
data/test/test_iron_mq.rb CHANGED
@@ -19,7 +19,7 @@ class IronMQTests < TestBase
19
19
  end
20
20
 
21
21
  def test_performance_post_100_messages
22
- @client.queue_name = 'test_basics3'
22
+ @client.queue_name = 'test_basics_6'
23
23
  # slower to rackspace since this is running on aws
24
24
  timeout = @client.host.include?('rackspace') ? 40 : 12
25
25
  assert_performance timeout do
@@ -31,7 +31,8 @@ class IronMQTests < TestBase
31
31
 
32
32
 
33
33
  def test_basics
34
- @client.queue_name = 'test_basics3'
34
+ queue_name = 'test_basics_6'
35
+ @client.queue_name = queue_name
35
36
  clear_queue
36
37
 
37
38
  res = @client.messages.post("hello world!")
@@ -42,7 +43,7 @@ class IronMQTests < TestBase
42
43
 
43
44
  queue = @client.queues.get(:name => @client.queue_name)
44
45
  p queue
45
- assert queue.size == 1
46
+ assert queue.reload.size == 1, "Size was not 1 after insert, it was: #{queue.size}"
46
47
  res = @client.messages.get()
47
48
  p res
48
49
  assert res["id"]
@@ -75,7 +76,7 @@ class IronMQTests < TestBase
75
76
 
76
77
 
77
78
  # new style of referencing queue
78
- queue = @client.queue("test_basics3")
79
+ queue = @client.queue(queue_name)
79
80
  v = "hello big world"
80
81
  res = queue.post(v)
81
82
  p res
@@ -113,7 +114,7 @@ class IronMQTests < TestBase
113
114
 
114
115
  # TODO: pass :timeout in post/get messages and test those
115
116
  def test_timeout
116
- @client.queue_name = "test_timeout"
117
+ @client.queue_name = "test_timeout_6"
117
118
  clear_queue
118
119
 
119
120
  res = @client.messages.post("hello world timeout!")
@@ -185,7 +186,7 @@ class IronMQTests < TestBase
185
186
  assert res.size == 0
186
187
 
187
188
 
188
- queue = @client.queue("test_basics3")
189
+ queue = @client.queue("test_basics_6")
189
190
  assert queue.name
190
191
  assert queue.size
191
192
 
@@ -194,7 +195,7 @@ class IronMQTests < TestBase
194
195
 
195
196
  def test_delay
196
197
  puts 'test_delay'
197
- @client.queue_name = "test_delay"
198
+ @client.queue_name = "test_delay_6"
198
199
  clear_queue
199
200
  msgTxt = "testMessage-"+Time.now.to_s
200
201
  puts msgTxt
@@ -210,7 +211,7 @@ class IronMQTests < TestBase
210
211
 
211
212
  def test_batch
212
213
  puts 'test_batch'
213
- @client.queue_name = "test_batch"
214
+ @client.queue_name = "test_batch_6"
214
215
  clear_queue
215
216
 
216
217
  x = []
@@ -239,7 +240,7 @@ class IronMQTests < TestBase
239
240
 
240
241
  def test_release
241
242
  puts 'test_release'
242
- @client.queue_name = "test_release"
243
+ @client.queue_name = "test_release_6"
243
244
  clear_queue
244
245
  msgTxt = "testMessage-"+Time.now.to_s
245
246
  puts msgTxt
@@ -294,7 +295,7 @@ class IronMQTests < TestBase
294
295
 
295
296
  def test_clear
296
297
 
297
- q = @client.queue("clearer")
298
+ q = @client.queue("clearer_6")
298
299
 
299
300
  clear_queue(q.name)
300
301
 
@@ -308,14 +309,14 @@ class IronMQTests < TestBase
308
309
 
309
310
  q.reload
310
311
 
311
- assert q.size == 0
312
+ assert q.reload.size == 0, "Size was not zero after clear, it was: #{q.size}"
312
313
 
313
314
  end
314
315
 
315
316
 
316
317
 
317
318
  def test_poll
318
- queue = @client.queue("test_poll")
319
+ queue = @client.queue("test_poll_6")
319
320
  queue.clear
320
321
 
321
322
  v = "hello world"
@@ -328,11 +329,30 @@ class IronMQTests < TestBase
328
329
  assert msg.body.include?("hello")
329
330
  i += 1
330
331
  end
331
- assert i == 5
332
+ assert i == 5, "Polled #{i} messages, but there should have only been five messages in queue. "
332
333
 
333
- assert queue.reload.size == 0
334
+ assert queue.reload.size == 0, "Size was not zero after poll, it was: #{queue.size}"
334
335
 
335
336
  end
337
+ #
338
+ #def test_delete
339
+ # queue = @client.queue("test_delete")
340
+ # queue.post("hi")
341
+ # queue.reload
342
+ # old_id = queue.id
343
+ # queue.delete_queue
344
+ #
345
+ # puts "sleeping for a bit to let queue delete..."
346
+ # sleep 60
347
+ #
348
+ # queue.post("hi2")
349
+ # p queue
350
+ # queue.reload
351
+ # assert queue.id != old_id, "old_id: #{old_id} is equal to new id: #{queue.id}"
352
+ # assert queue.size == 1
353
+ # queue.get("").body == "hi2"
354
+ #
355
+ #end
336
356
 
337
357
 
338
358
  end
data/test/tmp.rb CHANGED
@@ -13,4 +13,4 @@ class IronMQTests < TestBase
13
13
 
14
14
  end
15
15
 
16
- end
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.1
4
+ version: 2.1.2
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-08-14 00:00:00.000000000 Z
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_core
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.2.0
21
+ version: 0.4.2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.2.0
29
+ version: 0.4.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: test-unit
32
32
  requirement: !ruby/object:Gem::Requirement