iron_mq 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,42 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iron_mq (1.9.1)
4
+ iron_mq (2.0.0)
5
5
  iron_core (>= 0.2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.2.8)
11
10
  beanstalk-client (1.1.1)
12
- concur (0.1.2)
13
- em-http-request
14
- em-http-request
15
- eventmachine
16
- eventmachine
11
+ concur (1.0.0)
17
12
  faraday
18
13
  faraday
19
- cookiejar (0.3.0)
20
- em-http-request (1.0.2)
21
- addressable (>= 2.2.3)
22
- cookiejar
23
- em-socksify
24
- eventmachine (>= 1.0.0.beta.4)
25
- http_parser.rb (>= 0.5.3)
26
- em-socksify (0.2.0)
27
- eventmachine (>= 1.0.0.beta.4)
28
- eventmachine (1.0.0.rc.4)
29
14
  faraday (0.8.1)
30
15
  multipart-post (~> 1.1)
31
- ffi (1.0.11)
32
- http_parser.rb (0.5.3)
33
- iron_core (0.2.0)
16
+ ffi (1.1.3)
17
+ iron_core (0.3.3)
34
18
  rest (>= 2.0.0)
35
19
  mime-types (1.19)
36
20
  multipart-post (1.1.5)
37
21
  net-http-persistent (2.7)
38
22
  rake (0.9.2.2)
39
- rest (2.0.0)
23
+ rest (2.0.2)
40
24
  net-http-persistent
41
25
  rest-client (>= 0.3.0)
42
26
  rest-client (1.6.7)
@@ -45,7 +29,7 @@ GEM
45
29
  typhoeus (0.4.2)
46
30
  ffi (~> 1.0)
47
31
  mime-types (~> 1.18)
48
- uber_config (0.0.3)
32
+ uber_config (0.0.6)
49
33
 
50
34
  PLATFORMS
51
35
  ruby
@@ -28,6 +28,13 @@ module IronMQ
28
28
  ret
29
29
  end
30
30
 
31
+ def clear(options={})
32
+ @client.logger.debug "Clearing queue #{options[:name]}"
33
+ r1 = @client.post("#{path(options)}/clear", options)
34
+ p r1
35
+ r1
36
+ end
37
+
31
38
  # options:
32
39
  # :name => can specify an alternative queue name
33
40
  def get(options={})
@@ -74,6 +81,10 @@ module IronMQ
74
81
  raw["name"]
75
82
  end
76
83
 
84
+ def reload
85
+ load_queue
86
+ end
87
+
77
88
  # Used if lazy loading
78
89
  def load_queue
79
90
  q = @client.queues.get(:name=>name)
@@ -82,6 +93,10 @@ module IronMQ
82
93
  q
83
94
  end
84
95
 
96
+ def clear()
97
+ @client.queues.clear(:name=>name)
98
+ end
99
+
85
100
  def size
86
101
  return raw["size"] if raw["size"]
87
102
  return @size if @size
@@ -109,6 +124,7 @@ module IronMQ
109
124
  def delete(id, options={})
110
125
  @client.messages.delete(id, options.merge(:queue_name=>name))
111
126
  end
127
+
112
128
  end
113
129
 
114
130
  end
@@ -1,3 +1,3 @@
1
1
  module IronMQ
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
data/test/long_run.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
  require 'concur'
3
+ require 'uber_config'
3
4
  begin
4
5
  require File.join(File.dirname(__FILE__), '..', 'lib', 'iron_mq')
5
6
  rescue Exception => ex
@@ -9,15 +10,11 @@ end
9
10
 
10
11
  require_relative 'long_run_worker'
11
12
 
12
- @config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "iron_mq_ruby", "config.yml")))
13
+ @config = UberConfig.load
13
14
  @num_to_add = 1000
14
15
 
15
- #IronWorker.configure do |c|
16
- # c.token = @config['iron_mq']['token']
17
- # c.project_id = @config['iron_mq']['project_id']
18
- #end
19
-
20
16
  worker = LongRunWorker.new
17
+ worker.queue_name = "concur5"
21
18
  worker.config = @config
22
19
  worker.num_to_add = @num_to_add
23
20
  worker.run
@@ -3,12 +3,12 @@ require 'iron_mq'
3
3
 
4
4
  class LongRunWorker
5
5
 
6
- attr_accessor :config, :num_to_add
6
+ attr_accessor :config, :num_to_add, :queue_name
7
7
 
8
8
  def run
9
9
 
10
10
  @client = IronMQ::Client.new(@config['iron'])
11
- @client.queue_name = 'ironmq-gem-long'
11
+ queue = @client.queue(queue_name)
12
12
 
13
13
  @error_count = 0
14
14
 
@@ -19,7 +19,7 @@ class LongRunWorker
19
19
  task = executor.execute do
20
20
  begin
21
21
  puts "POST #{i}..."
22
- res = @client.messages.post("hello world! #{i}")
22
+ res = queue.post("hello world! #{i}")
23
23
  rescue => ex
24
24
  puts "ERROR! #{ex.class.name}: #{ex.message} -- #{ex.backtrace.inspect}"
25
25
  @error_count += 1
@@ -34,26 +34,40 @@ class LongRunWorker
34
34
  puts "waiting #{i}, queue size=#{executor.queue_size}"
35
35
  sleep 2
36
36
  end
37
-
38
-
39
37
  put_time = (Time.now.to_f - start.to_f)
40
38
  puts "Finished pushing in #{put_time} seconds"
41
39
 
40
+ queue = @client.queue(queue_name)
41
+ queue_size_after_push = queue.size
42
+ puts "QUEUE SIZE: #{queue_size_after_push}"
43
+
42
44
  #exit if true
43
45
 
44
46
  start = Time.now
45
47
  puts "Getting and deleting #{@num_to_add} items at #{start}..."
46
48
  @num_to_add.times do |i|
47
- puts "GET #{i}..."
48
- res = @client.messages.get()
49
- p res
50
- puts "DELETE #{i}..."
51
- res = @client.messages.delete(res["id"])
52
- p res
49
+ task = executor.execute do
50
+ puts "GET #{i}..."
51
+ res = queue.get()
52
+ p res
53
+ puts "DELETE #{i}..."
54
+ res = queue.delete(res.id)
55
+ p res
56
+ end
57
+ end
58
+ i = 0
59
+ while executor.queue_size > 0 do
60
+ i += 1
61
+ puts "waiting #{i}, queue size=#{executor.queue_size}"
62
+ sleep 2
53
63
  end
54
64
 
65
+ queue = @client.queue(queue_name)
66
+
55
67
  puts "Finished pushing #{@num_to_add} items in #{put_time} seconds."
68
+ puts "QUEUE SIZE after push: #{queue_size_after_push}"
56
69
  puts "Finished getting and deleting #{@num_to_add} items in #{(Time.now.to_f - start.to_f)} seconds."
70
+ puts "QUEUE SIZE after delete: #{queue.size}"
57
71
  puts "Errors: #{@error_count}"
58
72
 
59
73
  executor.shutdown
data/test/quick_run.rb CHANGED
@@ -5,7 +5,7 @@ class QuickRun < TestBase
5
5
 
6
6
  def setup
7
7
  super
8
- @client.queue_name = 'ironmq-gem-quick'
8
+ @client.queue_name = 'ironmq-gem_quick'
9
9
  clear_queue
10
10
  end
11
11
 
@@ -25,7 +25,7 @@ class BeanstalkTests < TestBase
25
25
 
26
26
  def test_basics
27
27
  omit_if @skip # bypass this test if rackspace
28
- puts 'test_basics'
28
+ puts 'test_basics3'
29
29
 
30
30
  queue_name = "beanstalk_test"
31
31
  clear_queue(queue_name)
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_basics'
22
+ @client.queue_name = 'test_basics3'
23
23
  # slower to rackspace since this is running on aws
24
24
  timeout = @client.host.include?('rackspace') ? 40 : 10
25
25
  assert_performance timeout do
@@ -31,7 +31,7 @@ class IronMQTests < TestBase
31
31
 
32
32
 
33
33
  def test_basics
34
- @client.queue_name = 'test_basics'
34
+ @client.queue_name = 'test_basics3'
35
35
  clear_queue
36
36
 
37
37
  res = @client.messages.post("hello world!")
@@ -41,6 +41,7 @@ class IronMQTests < TestBase
41
41
  assert res.msg
42
42
 
43
43
  queue = @client.queues.get(:name => @client.queue_name)
44
+ p queue
44
45
  assert queue.size == 1
45
46
  res = @client.messages.get()
46
47
  p res
@@ -75,7 +76,7 @@ class IronMQTests < TestBase
75
76
 
76
77
 
77
78
  # new style of referencing queue
78
- queue = @client.queue("test_basics")
79
+ queue = @client.queue("test_basics3")
79
80
  v = "hello big world"
80
81
  res = queue.post(v)
81
82
  p res
@@ -185,7 +186,7 @@ class IronMQTests < TestBase
185
186
  assert res.size == 0
186
187
 
187
188
 
188
- queue = @client.queue("test_basics")
189
+ queue = @client.queue("test_basics3")
189
190
  assert queue.name
190
191
  assert queue.size
191
192
 
@@ -237,61 +238,62 @@ class IronMQTests < TestBase
237
238
  end
238
239
  end
239
240
 
240
- # PUT THIS BACK IN WHEN READY
241
- #def test_release
242
- # puts 'test_release'
243
- # @client.queue_name = "test_release"
244
- # clear_queue
245
- # msgTxt = "testMessage-"+Time.now.to_s
246
- # puts msgTxt
247
- # msg_id = @client.messages.post(msgTxt, {:timeout => 3600}).id
248
- # puts "msg_id: #{msg_id}"
249
- # msg = @client.messages.get
250
- # p msg
251
- # assert msg.id == msg_id
252
- # # Ok, so should have received same message, now let's release it quicker than the original timeout
253
- #
254
- # # but first, ensure the next get is nil
255
- # msg = @client.messages.get
256
- # p msg
257
- # assert msg.nil?
258
- #
259
- # # now release it instantly
260
- # @client.messages.release(msg_id)
261
- # msg = @client.messages.get
262
- # p msg
263
- # assert msg
264
- # assert msg.id == msg_id
265
- #
266
- # # ok, so should be reserved again
267
- # msgr = @client.messages.get
268
- # p msgr
269
- # assert msgr.nil?
270
- #
271
- # # let's release it in 10 seconds
272
- # @client.messages.release(msg_id, :delay=>10)
273
- # msg = @client.messages.get
274
- # p msg
275
- # assert msg.nil?
276
- #
277
- # sleep 11
278
- #
279
- # msg = @client.messages.get
280
- # p msg
281
- # assert msg
282
- #
283
- # msg.release(:delay => 5)
284
- # msg = @client.messages.get
285
- # p msg
286
- # assert msg.nil?
287
- #
288
- # sleep 6
289
- #
290
- # msg = @client.messages.get
291
- # p msg
292
- # assert msg
293
- #
294
- #end
241
+ def test_release
242
+ puts 'test_release'
243
+ @client.queue_name = "test_release"
244
+ clear_queue
245
+ msgTxt = "testMessage-"+Time.now.to_s
246
+ puts msgTxt
247
+ msg_id = @client.messages.post(msgTxt, {:timeout => 60*5}).id
248
+ puts "msg_id: #{msg_id}"
249
+ msg = @client.messages.get
250
+ p msg
251
+ assert msg.id == msg_id
252
+ # Ok, so should have received same message, now let's release it quicker than the original timeout
253
+
254
+ # but first, ensure the next get is nil
255
+ msg = @client.messages.get
256
+ p msg
257
+ assert msg.nil?
258
+
259
+ # now release it instantly
260
+ @client.messages.release(msg_id)
261
+ msg = @client.messages.get
262
+ p msg
263
+ assert msg
264
+ assert msg.id == msg_id
265
+
266
+ # ok, so should be reserved again
267
+ msgr = @client.messages.get
268
+ p msgr
269
+ assert msgr.nil?
270
+
271
+ # let's release it in 10 seconds
272
+ @client.messages.release(msg_id, :delay=>10)
273
+ msg = @client.messages.get
274
+ p msg
275
+ assert msg.nil?
276
+
277
+ sleep 11
278
+
279
+ msg = @client.messages.get
280
+ p msg
281
+ assert msg
282
+
283
+ msg.release(:delay => 5)
284
+ msg = @client.messages.get
285
+ p msg
286
+ assert msg.nil?
287
+
288
+ sleep 6
289
+
290
+ msg = @client.messages.get
291
+ p msg
292
+ assert msg
293
+
294
+ end
295
+
296
+
295
297
 
296
298
  end
297
299
 
data/test/tmp.rb ADDED
@@ -0,0 +1,37 @@
1
+ # Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml
2
+
3
+ #$abt_config = {:hello=>'abt_config_ya'}
4
+
5
+ gem 'test-unit'
6
+ require 'test/unit'
7
+ require 'yaml'
8
+ require_relative 'test_base'
9
+
10
+ class IronMQTests < TestBase
11
+ def setup
12
+ super
13
+
14
+ end
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
+ 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.0.0
4
+ version: 2.1.0
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-07-10 00:00:00.000000000 Z
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_core
@@ -165,6 +165,7 @@ files:
165
165
  - test/test_beanstalkd.rb
166
166
  - test/test_bulk.rb
167
167
  - test/test_iron_mq.rb
168
+ - test/tmp.rb
168
169
  homepage: https://github.com/iron-io/iron_mq_ruby
169
170
  licenses: []
170
171
  post_install_message:
@@ -198,3 +199,4 @@ test_files:
198
199
  - test/test_beanstalkd.rb
199
200
  - test/test_bulk.rb
200
201
  - test/test_iron_mq.rb
202
+ - test/tmp.rb