actually setting the timeout in restclient

This commit is contained in:
danielvincent 2010-12-05 01:53:36 -08:00
parent ecc537c737
commit 737e6084df
2 changed files with 4 additions and 3 deletions

View file

@ -3,7 +3,8 @@ module Jobs
@queue = :http
def self.perform(url, body, tries_remaining)
begin
RestClient.post(url, :xml => body, :timeout => 4){ |response, request, result, &block|
request = RestClient::Request.new(url, :xml => body, :timeout => 4)
request.post { |response, request, result, &block|
if [301, 302, 307].include? response.code
response.follow_redirection(request, result, &block)
else

View file

@ -6,11 +6,11 @@ describe Jobs::HttpPost do
@body = '<xml>California</xml>'
end
it 'POSTs to a given URL' do
RestClient.should_receive(:post).with(@url, {:xml=>@body}).and_return(true)
RestClient::Request.should_receive(:new).with(@url, :xml=>@body, :timeout => 4)
Jobs::HttpPost.perform(@url, @body, 3)
end
it 'retries' do
RestClient.should_receive(:post).with(@url, {:xml=>@body}).and_raise(SocketError)
RestClient::Request.should_receive(:new).with(@url, :xml=>@body, :timeout => 4)
Resque.should_receive(:enqueue).with(Jobs::HttpPost, @url, @body, 1).once
Jobs::HttpPost.perform(@url, @body, 2)
end