Skip to content

Commit

Permalink
Allow timeout on message get
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Shaw committed Nov 10, 2011
1 parent 60f138b commit 88262f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/ironmq/messages.rb
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions test/ironmq_tests.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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.