ironmq 1.2.5 → 1.2.6
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/README.markdown +5 -5
- data/Rakefile +2 -2
- data/VERSION.yml +2 -2
- data/ironmq.gemspec +6 -2
- data/lib/ironmq.rb +1 -0
- data/lib/ironmq/client.rb +11 -79
- data/lib/ironmq/messages.rb +78 -0
- data/test/ironmq_tests.rb +57 -2
- data/test/long_run.rb +30 -10
- metadata +38 -33
data/README.markdown
CHANGED
@@ -10,7 +10,7 @@ Install the gem:
|
|
10
10
|
|
11
11
|
Create an IronMQ client object:
|
12
12
|
|
13
|
-
@
|
13
|
+
@ironmq = IronMQ::Client.new('token'=>'MYTOKEN', 'project_id'=>'MYPROJECTID')
|
14
14
|
|
15
15
|
You can get your `token` and `project_id` at http://www.iron.io .
|
16
16
|
|
@@ -20,12 +20,12 @@ The Basics
|
|
20
20
|
|
21
21
|
**Push** a message on the queue:
|
22
22
|
|
23
|
-
|
24
|
-
p
|
23
|
+
msg = @ironmq.messages.post("hello world!")
|
24
|
+
p msg
|
25
25
|
|
26
26
|
**Pop** a message off the queue:
|
27
27
|
|
28
|
-
|
28
|
+
msg = @ironmq.messages.get()
|
29
29
|
p res
|
30
30
|
|
31
31
|
When you pop/get a message from the queue, it will NOT be deleted. It will eventually go back onto the queue after
|
@@ -33,7 +33,7 @@ a timeout if you don't delete it (default timeout is 10 minutes).
|
|
33
33
|
|
34
34
|
**Delete** a message from the queue:
|
35
35
|
|
36
|
-
res = @
|
36
|
+
res = msg.delete # or @ironmq.messages.delete(msg["id"])
|
37
37
|
p res
|
38
38
|
|
39
39
|
Delete a message from the queue when you're done with it.
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require '
|
5
|
+
require 'jeweler2'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "ironmq"
|
8
8
|
gem.summary = "Ruby client for IronMQ"
|
@@ -15,7 +15,7 @@ begin
|
|
15
15
|
end
|
16
16
|
Jeweler::GemcutterTasks.new
|
17
17
|
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler2"
|
19
19
|
end
|
20
20
|
|
21
21
|
require 'rake/testtask'
|
data/VERSION.yml
CHANGED
data/ironmq.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ironmq}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Travis Reeder}]
|
12
|
-
s.date = %q{2011-11-
|
12
|
+
s.date = %q{2011-11-10}
|
13
13
|
s.description = %q{Ruby client for IronMQ}
|
14
14
|
s.email = %q{travis@iron.io}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
"ironmq.gemspec",
|
23
23
|
"lib/ironmq.rb",
|
24
24
|
"lib/ironmq/client.rb",
|
25
|
+
"lib/ironmq/messages.rb",
|
25
26
|
"test/ironmq_tests.rb",
|
26
27
|
"test/long_run.rb"
|
27
28
|
]
|
@@ -36,11 +37,14 @@ Gem::Specification.new do |s|
|
|
36
37
|
|
37
38
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
38
39
|
s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
|
40
|
+
s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
|
39
41
|
else
|
40
42
|
s.add_dependency(%q<typhoeus>, [">= 0"])
|
43
|
+
s.add_dependency(%q<typhoeus>, [">= 0"])
|
41
44
|
end
|
42
45
|
else
|
43
46
|
s.add_dependency(%q<typhoeus>, [">= 0"])
|
47
|
+
s.add_dependency(%q<typhoeus>, [">= 0"])
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
data/lib/ironmq.rb
CHANGED
data/lib/ironmq/client.rb
CHANGED
@@ -40,7 +40,8 @@ module IronMQ
|
|
40
40
|
def common_req_hash
|
41
41
|
{
|
42
42
|
:headers=>{"Content-Type" => 'application/json',
|
43
|
-
"Authorization"=>"OAuth #{@token}"
|
43
|
+
"Authorization"=>"OAuth #{@token}",
|
44
|
+
"User-Agent"=>"IronMQ Ruby Client"}
|
44
45
|
}
|
45
46
|
end
|
46
47
|
|
@@ -51,10 +52,11 @@ module IronMQ
|
|
51
52
|
req_hash = common_req_hash
|
52
53
|
req_hash[:body] = params.to_json
|
53
54
|
response = Typhoeus::Request.post(url, req_hash)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
@logger.debug 'typhoeus response=' + response.inspect
|
56
|
+
res = check_response(response)
|
57
|
+
#@logger.debug 'response: ' + res.inspect
|
58
|
+
#body = response.body
|
59
|
+
#res = JSON.parse(body)
|
58
60
|
return res, response.code
|
59
61
|
end
|
60
62
|
|
@@ -74,10 +76,10 @@ module IronMQ
|
|
74
76
|
req_hash = common_req_hash
|
75
77
|
req_hash[:params] = params
|
76
78
|
response = Typhoeus::Request.delete(url, req_hash)
|
77
|
-
check_response(response)
|
78
|
-
body = response.body
|
79
|
-
res = JSON.parse(body)
|
80
|
-
|
79
|
+
res = check_response(response)
|
80
|
+
#body = response.body
|
81
|
+
#res = JSON.parse(body)
|
82
|
+
#@logger.debug 'response: ' + res.inspect
|
81
83
|
return res, response.code
|
82
84
|
end
|
83
85
|
|
@@ -114,76 +116,6 @@ module IronMQ
|
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
117
|
-
class Messages
|
118
|
-
|
119
|
-
attr_accessor :client
|
120
|
-
|
121
|
-
def initialize(client)
|
122
|
-
@client = client
|
123
|
-
end
|
124
|
-
|
125
|
-
def path(options={})
|
126
|
-
path = "/projects/#{@client.project_id}/queues/#{options[:queue_name] || @client.queue_name}/messages"
|
127
|
-
end
|
128
|
-
|
129
|
-
# options:
|
130
|
-
# :queue_name => can specify an alternative queue name
|
131
|
-
def get(options={})
|
132
|
-
begin
|
133
|
-
res, status = @client.get(path(options))
|
134
|
-
return Message.new(self, res)
|
135
|
-
rescue IronMQ::Error => ex
|
136
|
-
if ex.status == 404
|
137
|
-
return nil
|
138
|
-
end
|
139
|
-
raise ex
|
140
|
-
end
|
141
|
-
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
# options:
|
146
|
-
# :queue_name => can specify an alternative queue name
|
147
|
-
def post(payload, options={})
|
148
|
-
res, status = @client.post(path(options), :body=>payload)
|
149
|
-
return Message.new(self, res)
|
150
|
-
end
|
151
|
-
|
152
|
-
def delete(message_id, options={})
|
153
|
-
path2 = "#{self.path(options)}/#{message_id}"
|
154
|
-
res, status = @client.delete(path2)
|
155
|
-
res
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
class Message
|
161
|
-
|
162
|
-
def initialize(messages, res)
|
163
|
-
@messages = messages
|
164
|
-
@data = res
|
165
|
-
end
|
166
|
-
|
167
|
-
def raw
|
168
|
-
@data
|
169
|
-
end
|
170
|
-
|
171
|
-
def [](key)
|
172
|
-
raw[key]
|
173
|
-
end
|
174
|
-
|
175
|
-
def id
|
176
|
-
raw["id"]
|
177
|
-
end
|
178
|
-
|
179
|
-
def body
|
180
|
-
raw["body"]
|
181
|
-
end
|
182
|
-
|
183
|
-
def delete
|
184
|
-
@messages.delete(self.id)
|
185
|
-
end
|
186
|
-
end
|
187
119
|
|
188
120
|
end
|
189
121
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module IronMQ
|
2
|
+
class Messages
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def path(options={})
|
11
|
+
path = "/projects/#{@client.project_id}/queues/#{options[:queue_name] || @client.queue_name}/messages"
|
12
|
+
end
|
13
|
+
|
14
|
+
# options:
|
15
|
+
# :queue_name => can specify an alternative queue name
|
16
|
+
# :timeout => amount of time before message goes back on the queue
|
17
|
+
def get(options={})
|
18
|
+
begin
|
19
|
+
params = nil
|
20
|
+
if options[:timeout]
|
21
|
+
params = {:timeout => options[:timeout]}
|
22
|
+
end
|
23
|
+
res, status = @client.get(path(options), params)
|
24
|
+
return Message.new(self, res)
|
25
|
+
rescue IronMQ::Error => ex
|
26
|
+
if ex.status == 404
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
raise ex
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
# options:
|
36
|
+
# :queue_name => can specify an alternative queue name
|
37
|
+
def post(payload, options={})
|
38
|
+
res, status = @client.post(path(options), :body=>payload)
|
39
|
+
return Message.new(self, res)
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete(message_id, options={})
|
43
|
+
path2 = "#{self.path(options)}/#{message_id}"
|
44
|
+
res, status = @client.delete(path2)
|
45
|
+
res
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
class Message
|
51
|
+
|
52
|
+
def initialize(messages, res)
|
53
|
+
@messages = messages
|
54
|
+
@data = res
|
55
|
+
end
|
56
|
+
|
57
|
+
def raw
|
58
|
+
@data
|
59
|
+
end
|
60
|
+
|
61
|
+
def [](key)
|
62
|
+
raw[key]
|
63
|
+
end
|
64
|
+
|
65
|
+
def id
|
66
|
+
raw["id"]
|
67
|
+
end
|
68
|
+
|
69
|
+
def body
|
70
|
+
raw["body"]
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete
|
74
|
+
@messages.delete(self.id)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/test/ironmq_tests.rb
CHANGED
@@ -15,8 +15,17 @@ class IronMQTests < Test::Unit::TestCase
|
|
15
15
|
puts 'setup'
|
16
16
|
@config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "ironmq_gem", "test", "config.yml")))
|
17
17
|
@client = IronMQ::Client.new(@config['ironmq'])
|
18
|
-
|
18
|
+
#@client.logger.level = Logger::DEBUG
|
19
19
|
@client.queue_name = 'ironmq-gem-tests'
|
20
|
+
|
21
|
+
puts 'clearing queue'
|
22
|
+
while res = @client.messages.get()
|
23
|
+
p res
|
24
|
+
puts res.body.to_s
|
25
|
+
res.delete
|
26
|
+
end
|
27
|
+
puts 'cleared.'
|
28
|
+
|
20
29
|
end
|
21
30
|
|
22
31
|
def test_basics
|
@@ -25,9 +34,55 @@ class IronMQTests < Test::Unit::TestCase
|
|
25
34
|
|
26
35
|
res = @client.messages.get()
|
27
36
|
p res
|
28
|
-
|
37
|
+
|
29
38
|
res = @client.messages.delete(res["id"])
|
30
39
|
p res
|
40
|
+
puts "shouldn't be any more"
|
41
|
+
res = @client.messages.get()
|
42
|
+
p res
|
43
|
+
assert res.nil?
|
44
|
+
|
45
|
+
res = @client.messages.post("hello world 2!")
|
46
|
+
p res
|
47
|
+
|
48
|
+
msg = @client.messages.get()
|
49
|
+
p msg
|
50
|
+
|
51
|
+
res = msg.delete
|
52
|
+
p res
|
53
|
+
|
54
|
+
puts "shouldn't be any more"
|
55
|
+
res = @client.messages.get()
|
56
|
+
p res
|
57
|
+
assert res.nil?
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_timeout
|
61
|
+
res = @client.messages.post("hello world timeout!")
|
62
|
+
p res
|
63
|
+
|
64
|
+
msg = @client.messages.get()
|
65
|
+
p msg
|
66
|
+
|
67
|
+
msg4 = @client.messages.get()
|
68
|
+
p msg4
|
69
|
+
assert msg4.nil?
|
70
|
+
|
71
|
+
puts 'sleeping 45 seconds...'
|
72
|
+
sleep 45
|
73
|
+
|
74
|
+
msg3 = @client.messages.get()
|
75
|
+
p msg3
|
76
|
+
assert msg3.nil?
|
77
|
+
|
78
|
+
puts 'sleeping another 45 seconds...'
|
79
|
+
sleep 45
|
80
|
+
|
81
|
+
msg2 = @client.messages.get()
|
82
|
+
assert msg.id == msg2.id
|
83
|
+
|
84
|
+
msg2.delete
|
85
|
+
|
31
86
|
end
|
32
87
|
end
|
33
88
|
|
data/test/long_run.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'concur'
|
2
3
|
begin
|
3
4
|
require File.join(File.dirname(__FILE__), '../lib/ironmq')
|
4
5
|
rescue Exception => ex
|
@@ -8,30 +9,49 @@ end
|
|
8
9
|
|
9
10
|
@config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "ironmq_gem", "test", "config.yml")))
|
10
11
|
@client = IronMQ::Client.new(@config['ironmq'])
|
11
|
-
@client.queue_name = 'ironmq-gem-
|
12
|
+
@client.queue_name = 'ironmq-gem-long'
|
12
13
|
@num_to_add = @config['count']
|
13
14
|
|
14
15
|
start = Time.now
|
15
16
|
puts "Queuing #{@num_to_add} items at #{start}..."
|
17
|
+
executor = Concur::Executor.new_thread_pool_executor(50)
|
16
18
|
@num_to_add.times do |i|
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
20
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
|
+
|
21
38
|
put_time = (Time.now.to_f - start.to_f)
|
22
39
|
puts "Finished pushing in #{put_time} seconds"
|
23
40
|
|
41
|
+
exit if true
|
42
|
+
|
24
43
|
start = Time.now
|
25
44
|
puts "Getting and deleting #{@num_to_add} items at #{start}..."
|
26
45
|
@num_to_add.times do |i|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
33
52
|
end
|
34
53
|
|
35
54
|
puts "Finished pushing #{@num_to_add} items in #{put_time} seconds."
|
36
55
|
puts "Finished getting and deleting #{@num_to_add} items in #{(Time.now.to_f - start.to_f)} seconds."
|
37
56
|
|
57
|
+
executor.shutdown
|
metadata
CHANGED
@@ -1,71 +1,76 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ironmq
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.6
|
4
5
|
prerelease:
|
5
|
-
version: 1.2.5
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Travis Reeder
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: typhoeus
|
16
|
+
requirement: &17190840 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
17
23
|
prerelease: false
|
18
|
-
|
24
|
+
version_requirements: *17190840
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: typhoeus
|
27
|
+
requirement: &17190320 !ruby/object:Gem::Requirement
|
19
28
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
24
33
|
type: :runtime
|
25
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *17190320
|
26
36
|
description: Ruby client for IronMQ
|
27
37
|
email: travis@iron.io
|
28
38
|
executables: []
|
29
|
-
|
30
39
|
extensions: []
|
31
|
-
|
32
|
-
extra_rdoc_files:
|
40
|
+
extra_rdoc_files:
|
33
41
|
- README.markdown
|
34
|
-
files:
|
42
|
+
files:
|
35
43
|
- README.markdown
|
36
44
|
- Rakefile
|
37
45
|
- VERSION.yml
|
38
46
|
- ironmq.gemspec
|
39
47
|
- lib/ironmq.rb
|
40
48
|
- lib/ironmq/client.rb
|
49
|
+
- lib/ironmq/messages.rb
|
41
50
|
- test/ironmq_tests.rb
|
42
51
|
- test/long_run.rb
|
43
52
|
homepage: http://www.iron.io
|
44
53
|
licenses: []
|
45
|
-
|
46
54
|
post_install_message:
|
47
55
|
rdoc_options: []
|
48
|
-
|
49
|
-
require_paths:
|
56
|
+
require_paths:
|
50
57
|
- lib
|
51
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
59
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version:
|
57
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.9'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
65
|
none: false
|
59
|
-
requirements:
|
60
|
-
- -
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version:
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
63
70
|
requirements: []
|
64
|
-
|
65
71
|
rubyforge_project:
|
66
72
|
rubygems_version: 1.8.8
|
67
73
|
signing_key:
|
68
74
|
specification_version: 3
|
69
75
|
summary: Ruby client for IronMQ
|
70
76
|
test_files: []
|
71
|
-
|