iron_mq 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -142,7 +142,7 @@ module IronMQ
142
142
  def poll(options={}, &blk)
143
143
  sleep_duration = options[:sleep_duration] || 1
144
144
  while true
145
- p options
145
+ #p options
146
146
  msg = get(options)
147
147
  if msg.nil?
148
148
  if options[:break_if_nil]
@@ -150,9 +150,10 @@ module IronMQ
150
150
  else
151
151
  sleep sleep_duration
152
152
  end
153
+ else
154
+ yield msg
155
+ msg.delete
153
156
  end
154
- yield msg
155
- msg.delete
156
157
  end
157
158
  end
158
159
 
@@ -1,3 +1,3 @@
1
1
  module IronMQ
2
- VERSION = "2.1.2"
2
+ VERSION = "2.1.3"
3
3
  end
data/test/long_run.rb CHANGED
@@ -11,12 +11,16 @@ end
11
11
  require_relative 'long_run_worker'
12
12
 
13
13
  @config = UberConfig.load
14
- @num_to_add = 1000
14
+ @num_to_add = 10000
15
+
16
+ p @config
15
17
 
16
18
  worker = LongRunWorker.new
17
- worker.queue_name = "concur5"
18
19
  worker.config = @config
20
+ worker.queue_name = "concur8"
21
+ worker.num_threads = 100
19
22
  worker.num_to_add = @num_to_add
23
+ worker.skip_get_and_delete = false
20
24
  worker.run
21
25
  #worker.queue
22
26
  #status = worker.wait_until_complete
@@ -3,7 +3,7 @@ require 'iron_mq'
3
3
 
4
4
  class LongRunWorker
5
5
 
6
- attr_accessor :config, :num_to_add, :queue_name
6
+ attr_accessor :config, :num_to_add, :queue_name, :skip_get_and_delete, :num_threads
7
7
 
8
8
  def run
9
9
 
@@ -14,7 +14,7 @@ class LongRunWorker
14
14
 
15
15
  start = Time.now
16
16
  puts "Queuing #{@num_to_add} items at #{start}..."
17
- executor = Concur::Executor.new_thread_pool_executor(50)
17
+ executor = Concur::Executor.new_thread_pool_executor(num_threads || 20)
18
18
  @num_to_add.times do |i|
19
19
  task = executor.execute do
20
20
  begin
@@ -35,6 +35,7 @@ class LongRunWorker
35
35
  sleep 2
36
36
  end
37
37
  put_time = (Time.now.to_f - start.to_f)
38
+ sleep 1
38
39
  puts "Finished pushing in #{put_time} seconds"
39
40
 
40
41
  queue = @client.queue(queue_name)
@@ -43,23 +44,26 @@ class LongRunWorker
43
44
 
44
45
  #exit if true
45
46
 
46
- start = Time.now
47
- puts "Getting and deleting #{@num_to_add} items at #{start}..."
48
- @num_to_add.times do |i|
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
47
+ if skip_get_and_delete
48
+ start = Time.now
49
+ puts "Getting and deleting #{@num_to_add} items at #{start}..."
50
+ @num_to_add.times do |i|
51
+ task = executor.execute do
52
+ puts "GET #{i}..."
53
+ res = queue.get()
54
+ p res
55
+ puts "DELETE #{i}..."
56
+ res = queue.delete(res.id)
57
+ p res
58
+ end
56
59
  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
60
+ i = 0
61
+ while executor.queue_size > 0 do
62
+ i += 1
63
+ puts "waiting #{i}, queue size=#{executor.queue_size}"
64
+ sleep 2
65
+ end
66
+ sleep 1
63
67
  end
64
68
 
65
69
  queue = @client.queue(queue_name)
data/test/quick_run.rb CHANGED
@@ -1,4 +1,3 @@
1
- # Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml
2
1
  require_relative 'test_base'
3
2
 
4
3
  class QuickRun < TestBase
@@ -1,7 +1,3 @@
1
- # Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml
2
-
3
- #$abt_config = {:hello=>'abt_config_ya'}
4
-
5
1
  gem 'test-unit'
6
2
  require 'test/unit'
7
3
  require 'beanstalk-client'
data/test/test_iron_mq.rb CHANGED
@@ -1,7 +1,3 @@
1
- # Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml
2
-
3
- #$abt_config = {:hello=>'abt_config_ya'}
4
-
5
1
  gem 'test-unit'
6
2
  require 'test/unit'
7
3
  require 'yaml'
@@ -43,7 +39,7 @@ class IronMQTests < TestBase
43
39
 
44
40
  queue = @client.queues.get(:name => @client.queue_name)
45
41
  p queue
46
- assert queue.reload.size == 1, "Size was not 1 after insert, it was: #{queue.size}"
42
+ assert_equal 1, queue.reload.size
47
43
  res = @client.messages.get()
48
44
  p res
49
45
  assert res["id"]
@@ -54,10 +50,10 @@ class IronMQTests < TestBase
54
50
  puts "shouldn't be any more"
55
51
  res = @client.messages.get()
56
52
  p res
57
- assert res.nil?
53
+ assert_nil res
58
54
 
59
55
  queue = @client.queues.get(:name => @client.queue_name)
60
- assert queue.size == 0
56
+ assert_equal 0, queue.size
61
57
 
62
58
  res = @client.messages.post("hello world 2!")
63
59
  p res
@@ -72,7 +68,7 @@ class IronMQTests < TestBase
72
68
  puts "shouldn't be any more"
73
69
  res = @client.messages.get()
74
70
  p res
75
- assert res.nil?
71
+ assert_nil res
76
72
 
77
73
 
78
74
  # new style of referencing queue
@@ -86,14 +82,14 @@ class IronMQTests < TestBase
86
82
  p res
87
83
  assert res["id"]
88
84
  assert res.id
89
- assert res.body == v
85
+ assert_equal v, res.body
90
86
 
91
87
  res = queue.delete(res.id)
92
88
  p res
93
89
  puts "shouldn't be any more"
94
90
  res = queue.get()
95
91
  p res
96
- assert res.nil?
92
+ assert_nil res
97
93
 
98
94
  # test delete by item
99
95
  res = queue.post(v)
@@ -108,7 +104,7 @@ class IronMQTests < TestBase
108
104
  puts "shouldn't be any more"
109
105
  res = queue.get()
110
106
  p res
111
- assert res.nil?
107
+ assert_nil res
112
108
 
113
109
  end
114
110
 
@@ -126,21 +122,21 @@ class IronMQTests < TestBase
126
122
 
127
123
  msg4 = @client.messages.get()
128
124
  p msg4
129
- assert msg4.nil?
125
+ assert_nil msg4
130
126
 
131
127
  puts 'sleeping 45 seconds...'
132
128
  sleep 45
133
129
 
134
130
  msg3 = @client.messages.get()
135
131
  p msg3
136
- assert msg3.nil?
132
+ assert_nil msg3
137
133
 
138
134
  puts 'sleeping another 45 seconds...'
139
135
  sleep 45
140
136
 
141
137
  msg2 = @client.messages.get()
142
138
  assert msg2
143
- assert msg.id == msg2.id
139
+ assert_equal msg2.id, msg.id
144
140
 
145
141
  msg2.delete
146
142
 
@@ -152,12 +148,12 @@ class IronMQTests < TestBase
152
148
  assert msg
153
149
  msg4 = @client.messages.get()
154
150
  p msg4
155
- assert msg4.nil?
151
+ assert_nil msg4
156
152
  puts 'sleeping 15 seconds...'
157
153
  sleep 15
158
154
  msg2 = @client.messages.get()
159
155
  assert msg2
160
- assert msg.id == msg2.id
156
+ assert_equal msg2.id, msg.id
161
157
 
162
158
  end
163
159
 
@@ -183,7 +179,7 @@ class IronMQTests < TestBase
183
179
  res.each do |q|
184
180
  p q.name
185
181
  end
186
- assert res.size == 0
182
+ assert_equal 0, res.size
187
183
 
188
184
 
189
185
  queue = @client.queue("test_basics_6")
@@ -202,7 +198,7 @@ class IronMQTests < TestBase
202
198
  @client.messages.post(msgTxt, {:delay => 10})
203
199
  msg = @client.messages.get
204
200
  p msg
205
- assert msg.nil?
201
+ assert_nil msg
206
202
  sleep 10
207
203
  msg = @client.messages.get
208
204
  p msg
@@ -221,7 +217,7 @@ class IronMQTests < TestBase
221
217
  resp = @client.messages.post(x)
222
218
  assert resp["ids"]
223
219
  assert resp["ids"].is_a?(Array)
224
- assert resp["ids"].size == 10
220
+ assert_equal 10, resp["ids"].size
225
221
 
226
222
  msg = @client.messages.get()
227
223
  assert msg
@@ -248,31 +244,31 @@ class IronMQTests < TestBase
248
244
  puts "msg_id: #{msg_id}"
249
245
  msg = @client.messages.get
250
246
  p msg
251
- assert msg.id == msg_id
247
+ assert_equal msg_id, msg.id
252
248
  # Ok, so should have received same message, now let's release it quicker than the original timeout
253
249
 
254
250
  # but first, ensure the next get is nil
255
251
  msg = @client.messages.get
256
252
  p msg
257
- assert msg.nil?
253
+ assert_nil msg
258
254
 
259
255
  # now release it instantly
260
256
  @client.messages.release(msg_id)
261
257
  msg = @client.messages.get
262
258
  p msg
263
259
  assert msg
264
- assert msg.id == msg_id
260
+ assert_equal msg_id, msg.id
265
261
 
266
262
  # ok, so should be reserved again
267
263
  msgr = @client.messages.get
268
264
  p msgr
269
- assert msgr.nil?
265
+ assert_nil msgr
270
266
 
271
267
  # let's release it in 10 seconds
272
268
  @client.messages.release(msg_id, :delay => 10)
273
269
  msg = @client.messages.get
274
270
  p msg
275
- assert msg.nil?
271
+ assert_nil msg
276
272
 
277
273
  sleep 11
278
274
 
@@ -283,7 +279,7 @@ class IronMQTests < TestBase
283
279
  msg.release(:delay => 5)
284
280
  msg = @client.messages.get
285
281
  p msg
286
- assert msg.nil?
282
+ assert_nil msg
287
283
 
288
284
  sleep 6
289
285
 
@@ -301,16 +297,16 @@ class IronMQTests < TestBase
301
297
 
302
298
  val = "hi mr clean"
303
299
  q.post(val)
304
- assert q.size == 1
305
300
 
306
- q.clear
307
- msg = q.get
308
- assert msg.nil?
301
+ sleep 0.5 # make sure the counter has time to update
302
+ assert_equal 1, q.size
309
303
 
310
- q.reload
304
+ q.clear
311
305
 
312
- assert q.reload.size == 0, "Size was not zero after clear, it was: #{q.size}"
306
+ msg = q.get
307
+ assert_nil msg
313
308
 
309
+ assert_equal 0, q.reload.size
314
310
  end
315
311
 
316
312
 
@@ -329,9 +325,10 @@ class IronMQTests < TestBase
329
325
  assert msg.body.include?("hello")
330
326
  i += 1
331
327
  end
332
- assert i == 5, "Polled #{i} messages, but there should have only been five messages in queue. "
333
328
 
334
- assert queue.reload.size == 0, "Size was not zero after poll, it was: #{queue.size}"
329
+ assert_equal 5, i
330
+
331
+ assert_equal 0, queue.reload.size
335
332
 
336
333
  end
337
334
  #
data/test/tmp.rb CHANGED
@@ -1,7 +1,3 @@
1
- # Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml
2
-
3
- #$abt_config = {:hello=>'abt_config_ya'}
4
-
5
1
  gem 'test-unit'
6
2
  require 'test/unit'
7
3
  require 'yaml'
@@ -11,6 +7,39 @@ class IronMQTests < TestBase
11
7
  def setup
12
8
  super
13
9
 
10
+ @queue_name = "fixed_num2_migration"
11
+
12
+ end
13
+
14
+ def test_put_x
15
+ q = @client.queue(@queue_name)
16
+ 1000.times do |i|
17
+ puts "#{i}"
18
+ q.post("msg #{i}")
19
+ end
20
+ p q.reload.size
21
+ assert_equal 1800, q.size
22
+ end
23
+
24
+ def test_get_x
25
+ #q = @client.queue(@queue_name)
26
+ #puts "q.size: #{q.size}"
27
+ #100.times do |i|
28
+ # puts "#{i}"
29
+ # msg = q.get
30
+ # msg.delete
31
+ #end
32
+ #p q.reload.size
33
+ #assert_equal 900, q.reload.size
14
34
  end
35
+ #
36
+ #def test_poll_all
37
+ # q = @client.queue(@queue_name)
38
+ # puts "q.size: #{q.size}"
39
+ # q.poll do |msg|
40
+ # p msg
41
+ # end
42
+ # p queue.reload.size
43
+ #end
15
44
 
16
45
  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.2
4
+ version: 2.1.3
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-23 00:00:00.000000000 Z
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_core