incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Wagner <matt.wag...@redhat.com>
Subject [PATCH] Adds timeout support to request method.
Date Thu, 17 Feb 2011 19:58:51 GMT
:open_timeout and :timeout can be specified, but default to
10 and 45 seconds, respectively. If exceeded, a RestClient::RequestTimeout
exception is raised.
---
  client/lib/deltacloud.rb |   10 +++++++---
  1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index 9975dc4..de747e9 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -315,14 +315,17 @@ module DeltaCloud
          :method => (args[0] || 'get').to_sym,
          :path => (args[1]=~/^http/) ? args[1] : 
"#{api_uri.to_s}#{args[1]}",
          :query_args => args[2] || {},
-        :form_data => args[3] || {}
+        :form_data => args[3] || {},
+        :timeout => args[4] || 45,
+        :open_timeout => args[5] || 10
        }
        if conf[:query_args] != {}
          conf[:path] += '?' + URI.escape(conf[:query_args].collect{ 
|key, value| "#{key}=#{value}" }.join('&')).to_s
        end

        if conf[:method].eql?(:post)
-        RestClient.send(:post, conf[:path], conf[:form_data], 
default_headers.merge(extended_headers)) do |response, request, block|
+        resource = RestClient::Resource.new(conf[:path], :open_timeout 
=> conf[:open_timeout], :timeout => conf[:timeout])
+        resource.send(:post, conf[:form_data], 
default_headers.merge(extended_headers)) do |response, request, block|
            handle_backend_error(response) if response.code.eql?(500)
            if response.respond_to?('body')
              yield response.body if block_given?
@@ -331,7 +334,8 @@ module DeltaCloud
            end
          end
        else
-        RestClient.send(conf[:method], conf[:path], 
default_headers.merge(extended_headers)) do |response, request, block|
+        resource = RestClient::Resource.new(conf[:path], :open_timeout 
=> conf[:open_timeout], :timeout => conf[:timeout])
+        resource.send(conf[:method], 
default_headers.merge(extended_headers)) do |response, request, block|
            handle_backend_error(response) if response.code.eql?(500)
            if conf[:method].eql?(:get) and [301, 302, 307].include? 
response.code
              response.follow_redirection(request) do |response, 
request, block|
-- 
1.7.4


Mime
View raw message