iron_mq 1.4.0 → 1.4.1
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.
- data/VERSION.yml +2 -2
- data/iron_mq.gemspec +6 -3
- data/lib/iron_mq/client.rb +2 -1
- data/lib/iron_mq/queues.rb +9 -1
- data/test/Gemfile +4 -0
- data/test/Gemfile.lock +38 -0
- data/test/long_run.rb +13 -40
- data/test/long_run_worker.rb +61 -0
- data/test/test_iron_mq.rb +37 -4
- metadata +14 -11
data/VERSION.yml
CHANGED
data/iron_mq.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "iron_mq"
|
8
|
-
s.version = "1.4.
|
8
|
+
s.version = "1.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Travis Reeder"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-02-08"
|
13
13
|
s.description = "Ruby client for IronMQ"
|
14
14
|
s.email = "travis@iron.io"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,7 +24,10 @@ Gem::Specification.new do |s|
|
|
24
24
|
"lib/iron_mq/client.rb",
|
25
25
|
"lib/iron_mq/messages.rb",
|
26
26
|
"lib/iron_mq/queues.rb",
|
27
|
+
"test/Gemfile",
|
28
|
+
"test/Gemfile.lock",
|
27
29
|
"test/long_run.rb",
|
30
|
+
"test/long_run_worker.rb",
|
28
31
|
"test/quick_run.rb",
|
29
32
|
"test/test_base.rb",
|
30
33
|
"test/test_iron_mq.rb"
|
@@ -32,7 +35,7 @@ Gem::Specification.new do |s|
|
|
32
35
|
s.homepage = "http://www.iron.io"
|
33
36
|
s.require_paths = ["lib"]
|
34
37
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9")
|
35
|
-
s.rubygems_version = "1.8.
|
38
|
+
s.rubygems_version = "1.8.15"
|
36
39
|
s.summary = "Ruby client for IronMQ"
|
37
40
|
|
38
41
|
if s.respond_to? :specification_version then
|
data/lib/iron_mq/client.rb
CHANGED
data/lib/iron_mq/queues.rb
CHANGED
@@ -60,7 +60,15 @@ module IronMQ
|
|
60
60
|
return @size if @size
|
61
61
|
q = @queues.get(:name=>name)
|
62
62
|
@size = q.size
|
63
|
-
|
63
|
+
@size
|
64
|
+
end
|
65
|
+
|
66
|
+
def total_messages
|
67
|
+
return raw["total_messages"] if raw["total_messages"]
|
68
|
+
return @total_messages if @total_messages
|
69
|
+
q = @queues.get(:name=>name)
|
70
|
+
@total_messages = q.total_messages
|
71
|
+
@total_messages
|
64
72
|
end
|
65
73
|
|
66
74
|
# def delete
|
data/test/Gemfile
ADDED
data/test/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.6)
|
5
|
+
beanstalk-client (1.1.1)
|
6
|
+
concur (0.1.2)
|
7
|
+
em-http-request
|
8
|
+
em-http-request
|
9
|
+
eventmachine
|
10
|
+
eventmachine
|
11
|
+
faraday
|
12
|
+
faraday
|
13
|
+
cookiejar (0.3.0)
|
14
|
+
em-http-request (1.0.1)
|
15
|
+
addressable (>= 2.2.3)
|
16
|
+
cookiejar
|
17
|
+
em-socksify
|
18
|
+
eventmachine (>= 1.0.0.beta.4)
|
19
|
+
http_parser.rb (>= 0.5.3)
|
20
|
+
em-socksify (0.1.0)
|
21
|
+
eventmachine
|
22
|
+
eventmachine (1.0.0.beta.4)
|
23
|
+
faraday (0.7.5)
|
24
|
+
addressable (~> 2.2.6)
|
25
|
+
multipart-post (~> 1.1.3)
|
26
|
+
rack (>= 1.1.0, < 2)
|
27
|
+
http_parser.rb (0.5.3)
|
28
|
+
multipart-post (1.1.4)
|
29
|
+
rack (1.4.0)
|
30
|
+
test-unit (2.4.4)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
beanstalk-client
|
37
|
+
concur
|
38
|
+
test-unit
|
data/test/long_run.rb
CHANGED
@@ -7,51 +7,24 @@ rescue Exception => ex
|
|
7
7
|
raise ex
|
8
8
|
end
|
9
9
|
|
10
|
+
require_relative 'long_run_worker'
|
11
|
+
|
10
12
|
@config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "iron_mq_ruby", "test", "config.yml")))
|
11
|
-
@client = IronMQ::Client.new(@config['ironmq'])
|
12
|
-
@client.queue_name = 'ironmq-gem-long'
|
13
13
|
@num_to_add = @config['count']
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@num_to_add.times do |i|
|
19
|
-
task = executor.execute do
|
20
|
-
begin
|
21
|
-
puts "POST #{i}..."
|
22
|
-
res = @client.messages.post("hello world! #{i}")
|
23
|
-
rescue => ex
|
24
|
-
puts "ERROR! #{ex.class.name}: #{ex.message} -- #{ex.backtrace.inspect}"
|
25
|
-
raise ex
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
i = 0
|
31
|
-
while executor.queue_size > 0 do
|
32
|
-
i += 1
|
33
|
-
puts "waiting #{i}, queue size=#{executor.queue_size}"
|
34
|
-
sleep 0.5
|
15
|
+
IronWorker.configure do |c|
|
16
|
+
c.token = @config['iron_mq']['token']
|
17
|
+
c.project_id = @config['iron_mq']['project_id']
|
35
18
|
end
|
36
19
|
|
20
|
+
worker = LongRunWorker.new
|
21
|
+
worker.config = @config
|
22
|
+
worker.num_to_add = @num_to_add
|
23
|
+
#worker.run_local
|
24
|
+
worker.queue
|
25
|
+
status = worker.wait_until_complete
|
26
|
+
p status
|
27
|
+
puts worker.get_log
|
37
28
|
|
38
|
-
put_time = (Time.now.to_f - start.to_f)
|
39
|
-
puts "Finished pushing in #{put_time} seconds"
|
40
|
-
|
41
|
-
exit if true
|
42
|
-
|
43
|
-
start = Time.now
|
44
|
-
puts "Getting and deleting #{@num_to_add} items at #{start}..."
|
45
|
-
@num_to_add.times do |i|
|
46
|
-
puts "GET #{i}..."
|
47
|
-
res = @client.messages.get()
|
48
|
-
p res
|
49
|
-
puts "DELETE #{i}..."
|
50
|
-
res = @client.messages.delete(res["id"])
|
51
|
-
p res
|
52
|
-
end
|
53
29
|
|
54
|
-
puts "Finished pushing #{@num_to_add} items in #{put_time} seconds."
|
55
|
-
puts "Finished getting and deleting #{@num_to_add} items in #{(Time.now.to_f - start.to_f)} seconds."
|
56
30
|
|
57
|
-
executor.shutdown
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'iron_worker'
|
2
|
+
|
3
|
+
class LongRunWorker < IronWorker::Base
|
4
|
+
|
5
|
+
merge_gem 'concur'
|
6
|
+
merge_gem 'iron_mq'
|
7
|
+
|
8
|
+
attr_accessor :config, :num_to_add
|
9
|
+
|
10
|
+
def run
|
11
|
+
|
12
|
+
@client = IronMQ::Client.new(@config['iron_mq'])
|
13
|
+
@client.queue_name = 'ironmq-gem-long'
|
14
|
+
|
15
|
+
start = Time.now
|
16
|
+
puts "Queuing #{@num_to_add} items at #{start}..."
|
17
|
+
executor = Concur::Executor.new_thread_pool_executor(20)
|
18
|
+
@num_to_add.times do |i|
|
19
|
+
task = executor.execute do
|
20
|
+
begin
|
21
|
+
puts "POST #{i}..."
|
22
|
+
res = @client.messages.post("hello world! #{i}")
|
23
|
+
rescue => ex
|
24
|
+
puts "ERROR! #{ex.class.name}: #{ex.message} -- #{ex.backtrace.inspect}"
|
25
|
+
raise ex
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
i = 0
|
31
|
+
while executor.queue_size > 0 do
|
32
|
+
i += 1
|
33
|
+
puts "waiting #{i}, queue size=#{executor.queue_size}"
|
34
|
+
sleep 0.5
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
put_time = (Time.now.to_f - start.to_f)
|
39
|
+
puts "Finished pushing in #{put_time} seconds"
|
40
|
+
|
41
|
+
#exit if true
|
42
|
+
|
43
|
+
start = Time.now
|
44
|
+
puts "Getting and deleting #{@num_to_add} items at #{start}..."
|
45
|
+
@num_to_add.times do |i|
|
46
|
+
puts "GET #{i}..."
|
47
|
+
res = @client.messages.get()
|
48
|
+
p res
|
49
|
+
puts "DELETE #{i}..."
|
50
|
+
res = @client.messages.delete(res["id"])
|
51
|
+
p res
|
52
|
+
end
|
53
|
+
|
54
|
+
puts "Finished pushing #{@num_to_add} items in #{put_time} seconds."
|
55
|
+
puts "Finished getting and deleting #{@num_to_add} items in #{(Time.now.to_f - start.to_f)} seconds."
|
56
|
+
|
57
|
+
executor.shutdown
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/test/test_iron_mq.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
gem 'test-unit'
|
6
6
|
require 'test/unit'
|
7
|
+
require 'beanstalk-client'
|
7
8
|
require 'yaml'
|
8
9
|
require_relative 'test_base'
|
9
10
|
|
@@ -15,11 +16,13 @@ class IronMQTests < TestBase
|
|
15
16
|
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
19
|
def test_basics
|
20
20
|
@client.queue_name = 'test_basics'
|
21
21
|
clear_queue
|
22
22
|
|
23
|
+
queue = @client.queues.get(:name=>@client.queue_name)
|
24
|
+
total_messages = queue.total_messages
|
25
|
+
|
23
26
|
res = @client.messages.post("hello world!")
|
24
27
|
p res
|
25
28
|
assert res["id"]
|
@@ -28,7 +31,7 @@ class IronMQTests < TestBase
|
|
28
31
|
|
29
32
|
queue = @client.queues.get(:name=>@client.queue_name)
|
30
33
|
assert queue.size == 1
|
31
|
-
|
34
|
+
assert queue.total_messages == (total_messages+1)
|
32
35
|
res = @client.messages.get()
|
33
36
|
p res
|
34
37
|
assert res["id"]
|
@@ -155,9 +158,39 @@ class IronMQTests < TestBase
|
|
155
158
|
msgs.each do |m|
|
156
159
|
m.delete
|
157
160
|
end
|
158
|
-
|
159
|
-
|
160
161
|
end
|
161
162
|
|
163
|
+
def test_beanstalk
|
164
|
+
puts 'test_beanstalk'
|
165
|
+
config = @config['iron_mq']
|
166
|
+
h = "#{config['host']||"mq-aws-us-east-1.iron.io"}:#{config['beanstalkd_port']||11300}"
|
167
|
+
beanstalk = Beanstalk::Connection.new(h)
|
168
|
+
beanstalk.put("oauth #{config['token']} #{config['project_id']}")
|
169
|
+
beanstalk.use(@client.queue_name)
|
170
|
+
beanstalk.watch(@client.queue_name)
|
171
|
+
|
172
|
+
msg = "hello #{Time.now}"
|
173
|
+
beanstalk.put(msg)
|
174
|
+
job = beanstalk.reserve
|
175
|
+
assert_equal msg, job.body, "body not the same as message."
|
176
|
+
job.delete
|
177
|
+
job = assert_raise(Beanstalk::TimedOut) {
|
178
|
+
beanstalk.reserve(1)
|
179
|
+
}
|
180
|
+
|
181
|
+
hasher = {:x=>1, :y=>"hello", "yo"=>"scooby doo"}
|
182
|
+
beanstalk.put(hasher.to_json)
|
183
|
+
job = beanstalk.reserve(1)
|
184
|
+
got = JSON.parse(job.body)
|
185
|
+
assert got.is_a?(Hash)
|
186
|
+
assert_equal hasher[:x], got['x']
|
187
|
+
job.delete
|
188
|
+
|
189
|
+
msg = "hello there\nthis is a new line"
|
190
|
+
beanstalk.put(msg)
|
191
|
+
job = beanstalk.reserve(1)
|
192
|
+
assert_equal msg, job.body, "#{job.body} does not equal #{msg}"
|
193
|
+
job.delete
|
194
|
+
end
|
162
195
|
end
|
163
196
|
|
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: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement: &
|
16
|
+
requirement: &22831660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *22831660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rest
|
27
|
-
requirement: &
|
27
|
+
requirement: &22830400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *22830400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rest-client
|
38
|
-
requirement: &
|
38
|
+
requirement: &22829360 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *22829360
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rest
|
49
|
-
requirement: &
|
49
|
+
requirement: &22828720 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *22828720
|
58
58
|
description: Ruby client for IronMQ
|
59
59
|
email: travis@iron.io
|
60
60
|
executables: []
|
@@ -70,7 +70,10 @@ files:
|
|
70
70
|
- lib/iron_mq/client.rb
|
71
71
|
- lib/iron_mq/messages.rb
|
72
72
|
- lib/iron_mq/queues.rb
|
73
|
+
- test/Gemfile
|
74
|
+
- test/Gemfile.lock
|
73
75
|
- test/long_run.rb
|
76
|
+
- test/long_run_worker.rb
|
74
77
|
- test/quick_run.rb
|
75
78
|
- test/test_base.rb
|
76
79
|
- test/test_iron_mq.rb
|
@@ -94,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
97
|
version: '0'
|
95
98
|
requirements: []
|
96
99
|
rubyforge_project:
|
97
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.15
|
98
101
|
signing_key:
|
99
102
|
specification_version: 3
|
100
103
|
summary: Ruby client for IronMQ
|