Permalink
Browse files

Allow timeout on message get

  • Loading branch information...
1 parent 60f138b commit 88262f8b311270b49c8007a4969ce794e3f37924 Evan Shaw committed Nov 10, 2011
Showing with 24 additions and 4 deletions.
  1. +6 −1 lib/ironmq/messages.rb
  2. +18 −3 test/ironmq_tests.rb
View
@@ -13,9 +13,14 @@ def path(options={})
# options:
# :queue_name => can specify an alternative queue name
+ # :timeout => amount of time before message goes back on the queue
def get(options={})
begin
- res, status = @client.get(path(options))
+ params = nil
+ if options[:timeout]
+ params = {:timeout => options[:timeout]}
+ end
+ res, status = @client.get(path(options), params)
return Message.new(self, res)
rescue IronMQ::Error => ex
if ex.status == 404
View
@@ -19,9 +19,7 @@ def setup
@client.queue_name = 'ironmq-gem-tests'
puts 'clearing queue'
- res = nil
- while res != nil
- res = @client.messages.get()
+ while res = @client.messages.get()
p res
puts res.body.to_s
res.delete
@@ -86,5 +84,22 @@ def test_timeout
msg2.delete
end
+
+ def test_consumer_timeout
+ res = @client.messages.post("hello world consumer timeout!")
+ p res
+
+ msg = @client.messages.get(:timeout => 2)
+ assert_not_nil msg
+
+ msg3 = @client.messages.get()
+ assert msg3.nil?
+
+ sleep 2
+ msg2 = @client.messages.get()
+ assert_equal msg2.id, msg.id
+
+ msg2.delete
+ end
end

0 comments on commit 88262f8

Please sign in to comment.