iron_mq 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 3
4
- :patch: 1
3
+ :minor: 4
4
+ :patch: 0
5
5
  :build:
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.3.1"
8
+ s.version = "1.4.0"
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-01-04"
12
+ s.date = "2012-01-05"
13
13
  s.description = "Ruby client for IronMQ"
14
14
  s.email = "travis@iron.io"
15
15
  s.extra_rdoc_files = [
@@ -17,7 +17,20 @@ module IronMQ
17
17
  def get(options={})
18
18
  begin
19
19
  res, status = @client.get(path(options), options)
20
- return Message.new(self, res)
20
+ @client.logger.debug "GET response: " + res.inspect
21
+ ret = []
22
+ res["messages"].each do |m|
23
+ ret << Message.new(self, m)
24
+ end
25
+ if options[:n]
26
+ return ret
27
+ else
28
+ if ret.size > 0
29
+ return ret[0]
30
+ else
31
+ return nil
32
+ end
33
+ end
21
34
  rescue IronMQ::Error => ex
22
35
  if ex.status == 404
23
36
  return nil
@@ -25,7 +38,6 @@ module IronMQ
25
38
  raise ex
26
39
  end
27
40
 
28
-
29
41
  end
30
42
 
31
43
  # options:
@@ -34,9 +46,24 @@ module IronMQ
34
46
  # :timeout => The time in seconds to wait after message is taken off the queue, before it is put back on. Delete before :timeout to ensure it does not go back on the queue.
35
47
  # :expires_in => After this time, message will be automatically removed from the queue.
36
48
  def post(payload, options={})
37
- options[:body] = payload
38
- res, status = @client.post(path(options), options)
39
- return Message.new(self, res)
49
+ batch = false
50
+ if payload.is_a?(Array)
51
+ batch = true
52
+ msgs = payload
53
+ else
54
+ options[:body] = payload
55
+ msgs = []
56
+ msgs << options
57
+ end
58
+ to_send = {}
59
+ to_send[:messages] = msgs
60
+ res, status = @client.post(path(options), to_send)
61
+ #return Message.new(self, res)
62
+ if batch
63
+ return res
64
+ else
65
+ return ResponseBase.new({"id"=>res["ids"][0], "msg"=>res["msg"]})
66
+ end
40
67
  end
41
68
 
42
69
  def delete(message_id, options={})
@@ -47,10 +74,8 @@ module IronMQ
47
74
 
48
75
  end
49
76
 
50
- class Message
51
-
52
- def initialize(messages, res)
53
- @messages = messages
77
+ class ResponseBase
78
+ def initialize(res)
54
79
  @data = res
55
80
  end
56
81
 
@@ -66,6 +91,20 @@ module IronMQ
66
91
  raw["id"]
67
92
  end
68
93
 
94
+ def msg
95
+ raw["msg"]
96
+ end
97
+
98
+ end
99
+
100
+ class Message < ResponseBase
101
+
102
+ def initialize(messages, res)
103
+ super(res)
104
+ @messages = messages
105
+ end
106
+
107
+
69
108
  def body
70
109
  raw["body"]
71
110
  end
data/test/test_base.rb CHANGED
@@ -4,7 +4,7 @@ require 'yaml'
4
4
  begin
5
5
  require File.join(File.dirname(__FILE__), '../lib/iron_mq')
6
6
  rescue Exception => ex
7
- puts "Could NOT load current ironmq: " + ex.message
7
+ puts "Could NOT load current iron_mq: " + ex.message
8
8
  raise ex
9
9
  end
10
10
 
@@ -23,6 +23,7 @@ class TestBase < Test::Unit::TestCase
23
23
 
24
24
  def load_config
25
25
  # check for config
26
+ # First check if running in abt worker
26
27
  if defined? $abt_config
27
28
  @config = $abt_config
28
29
  return @config
@@ -34,4 +35,18 @@ class TestBase < Test::Unit::TestCase
34
35
  end
35
36
 
36
37
  end
38
+
39
+
40
+ def clear_queue(queue_name=nil)
41
+ queue_name ||= @client.queue_name
42
+ puts "clearing queue #{queue_name}"
43
+ while res = @client.messages.get(:queue_name=>queue_name)
44
+ p res
45
+ puts res.body.to_s
46
+ res.delete
47
+ end
48
+ puts 'cleared.'
49
+ end
50
+
51
+
37
52
  end
data/test/test_iron_mq.rb CHANGED
@@ -11,25 +11,28 @@ class IronMQTests < TestBase
11
11
  def setup
12
12
  super
13
13
 
14
- puts 'clearing queue'
15
- while res = @client.messages.get()
16
- p res
17
- puts res.body.to_s
18
- res.delete
19
- end
20
- puts 'cleared.'
14
+ clear_queue()
21
15
 
22
16
  end
23
17
 
18
+
24
19
  def test_basics
20
+ @client.queue_name = 'test_basics'
21
+ clear_queue
25
22
 
26
23
  res = @client.messages.post("hello world!")
27
24
  p res
25
+ assert res["id"]
26
+ assert res.id
27
+ assert res.msg
28
+
28
29
  queue = @client.queues.get(:name=>@client.queue_name)
29
30
  assert queue.size == 1
30
31
 
31
32
  res = @client.messages.get()
32
33
  p res
34
+ assert res["id"]
35
+ assert res.id
33
36
 
34
37
  res = @client.messages.delete(res["id"])
35
38
  p res
@@ -46,6 +49,7 @@ class IronMQTests < TestBase
46
49
 
47
50
  msg = @client.messages.get()
48
51
  p msg
52
+ assert msg
49
53
 
50
54
  res = msg.delete
51
55
  p res
@@ -58,6 +62,9 @@ class IronMQTests < TestBase
58
62
 
59
63
  # TODO: pass :timeout in post/get messages and test those
60
64
  def test_timeout
65
+ @client.queue_name = "test_timeout"
66
+ clear_queue
67
+
61
68
  res = @client.messages.post("hello world timeout!")
62
69
  p res
63
70
 
@@ -87,7 +94,7 @@ class IronMQTests < TestBase
87
94
 
88
95
  def test_queues
89
96
  res = @client.queues.list()
90
- puts "res.size=" + res.size.to_s
97
+ puts "res.size: " + res.size.to_s
91
98
  res.each do |q|
92
99
  puts "queue_name: " + q.name
93
100
  puts "queue size: " + q.size.to_s
@@ -96,7 +103,7 @@ class IronMQTests < TestBase
96
103
  assert res.size > 0
97
104
 
98
105
  res = @client.queues.list(:page=>5)
99
- puts "res.size 2=" + res.size.to_s
106
+ puts "res.size 2: " + res.size.to_s
100
107
  res.each do |q|
101
108
  p q.name
102
109
  end
@@ -106,7 +113,50 @@ class IronMQTests < TestBase
106
113
  end
107
114
 
108
115
  def test_delay
109
- # TODO
116
+ puts 'test_delay'
117
+ @client.queue_name = "test_delay"
118
+ clear_queue
119
+ msgTxt = "testMessage-"+Time.now.to_s
120
+ puts msgTxt
121
+ @client.messages.post(msgTxt, {:delay => 10})
122
+ msg = @client.messages.get
123
+ p msg
124
+ assert msg.nil?
125
+ sleep 10
126
+ msg = @client.messages.get
127
+ p msg
128
+ assert msg
129
+ end
130
+
131
+ def test_batch
132
+ puts 'test_batch'
133
+ @client.queue_name = "test_batch"
134
+ clear_queue
135
+
136
+ x = []
137
+ 10.times do |i|
138
+ x << {:body=>"body #{i}"}
139
+ end
140
+ resp = @client.messages.post(x)
141
+ assert resp["ids"]
142
+ assert resp["ids"].is_a?(Array)
143
+ assert resp["ids"].size == 10
144
+
145
+ msg = @client.messages.get()
146
+ assert msg
147
+ assert msg['id']
148
+ msg.delete
149
+
150
+ msgs = @client.messages.get(:n=>10)
151
+ assert msgs.is_a?(Array)
152
+ assert msgs.size == 9, "size should be 9, but it's #{msgs.size}"
153
+ assert msgs[0]["id"]
154
+
155
+ msgs.each do |m|
156
+ m.delete
157
+ end
158
+
159
+
110
160
  end
111
161
 
112
162
  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: 1.3.1
4
+ version: 1.4.0
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-01-04 00:00:00.000000000 Z
12
+ date: 2012-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &12253800 !ruby/object:Gem::Requirement
16
+ requirement: &24074940 !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: *12253800
24
+ version_requirements: *24074940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest
27
- requirement: &12253220 !ruby/object:Gem::Requirement
27
+ requirement: &24074340 !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: *12253220
35
+ version_requirements: *24074340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rest-client
38
- requirement: &12252420 !ruby/object:Gem::Requirement
38
+ requirement: &24073540 !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: *12252420
46
+ version_requirements: *24073540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rest
49
- requirement: &12251440 !ruby/object:Gem::Requirement
49
+ requirement: &24072540 !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: *12251440
57
+ version_requirements: *24072540
58
58
  description: Ruby client for IronMQ
59
59
  email: travis@iron.io
60
60
  executables: []