Browse files

Merge branch 'master' of https://github.com/elkdotnet/aws into elkdot…

…net-master
  • Loading branch information...
2 parents a5b997f + 0ab7da5 commit 214e64e26ac1bfc26deefb059a615e98d796c51d @treeder treeder committed Jan 3, 2011
Showing with 43 additions and 0 deletions.
  1. +10 −0 lib/sqs/right_sqs.rb
  2. +14 −0 lib/sqs/right_sqs_interface.rb
  3. +19 −0 test/sqs/test_sqs.rb
View
10 lib/sqs/right_sqs.rb
@@ -279,6 +279,16 @@ def to_s
def delete
@queue.sqs.interface.delete_message(@queue.url, @receipt_handle) if @receipt_handle
end
+
+ # Updates visibility timeout.
+ def visibility=(visibility_timeout)
+ if @receipt_handle
+ @queue.sqs.interface.change_message_visibility(
+ @queue.url, @receipt_handle, visibility_timeout
+ )
+ @visibility = visibility_timeout
+ end
+ end
end
View
14 lib/sqs/right_sqs_interface.rb
@@ -278,6 +278,20 @@ def delete_message(queue_url, receipt_handle)
rescue
on_exception
end
+
+ # Sets new visibility timeout value for a message identified by "receipt_handle"
+ # Check out the Amazon SQS API documentation for further details.
+ def change_message_visibility(queue_url, receipt_handle, visibility_timeout)
+ req_hash = generate_request(
+ "ChangeMessageVisibility",
+ "ReceiptHandle" => receipt_handle,
+ "VisibilityTimeout" => visibility_timeout,
+ :queue_url => queue_url
+ )
+ request_info(req_hash, SqsStatusParser.new(:logger => @logger))
+ rescue
+ on_exception
+ end
# Given the queue's short name, this call returns the queue URL or +nil+ if queue is not found
# sqs.queue_url_by_name('my_awesome_queue') #=> 'http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue'
View
19 test/sqs/test_sqs.rb
@@ -202,5 +202,24 @@ def test_28_check_threading_model
newsqs = Aws::SqsInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, {:multi_thread => true})
assert(newsqs.multi_thread)
end
+
+ # Note that just like the other tests, this one does not clean up
+ # after itself (queue does not get deleted)
+ def test_29_change_message_visibility
+ queue = Aws::Sqs::Queue.create(@s, "#{@queue_name}_29", true, 10)
+ # Be sure the queue is empty. Useful when rerunning the tests.
+ queue.clear
+ queue.send_message(RIGHT_MESSAGE_TEXT)
+ m = nil
+ # Wait for the message to be delivered
+ while m.nil?
+ m = queue.receive
+ end
+ m.visibility = 60
+ sleep(20)
+ # Had the visibility timeout been not updated, the message would be available
+ # at this point.
+ assert queue.receive.nil?
+ end
end

0 comments on commit 214e64e

Please sign in to comment.