HttpPost job now follows redirects
This commit is contained in:
parent
177cc16e2f
commit
d1ad2efed1
3 changed files with 16 additions and 7 deletions
|
|
@ -3,10 +3,19 @@ module Jobs
|
|||
@queue = :http
|
||||
def self.perform(url, body, tries_remaining)
|
||||
begin
|
||||
RestClient.post(url, :xml => body)
|
||||
RestClient.post(url, :xml => body){ |response, request, result, &block|
|
||||
if [301, 302, 307].include? response.code
|
||||
response.follow_redirection(request, result, &block)
|
||||
else
|
||||
response.return!(request, result, &block)
|
||||
end
|
||||
}
|
||||
rescue Exception => e
|
||||
Resque.enqueue(self, url, body, tries_remaining -1) unless tries_remaining <= 1
|
||||
raise e
|
||||
unless tries_remaining <= 1
|
||||
Resque.enqueue(self, url, body, tries_remaining -1)
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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, @body).and_return(true)
|
||||
RestClient.should_receive(:post).with(@url, {:xml=>@body}).and_return(true)
|
||||
Jobs::HttpPost.perform(@url, @body, 3)
|
||||
end
|
||||
it 'retries' do
|
||||
RestClient.should_receive(:post).with(@url, @body).and_raise(SocketError)
|
||||
RestClient.should_receive(:post).with(@url, {:xml=>@body}).and_raise(SocketError)
|
||||
Resque.should_receive(:enqueue).with(Jobs::HttpPost, @url, @body, 1).once
|
||||
Jobs::HttpPost.perform(@url, @body, 2)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ RSpec.configure do |config|
|
|||
config.before(:each) do
|
||||
I18n.locale = :en
|
||||
EventMachine::HttpRequest.stub!(:new).and_return(FakeHttpRequest.new(:success))
|
||||
EventMachine::HttpRequest.any_instance.stubs(:post)
|
||||
EventMachine::HttpRequest.any_instance.stubs(:get)
|
||||
RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success))
|
||||
|
||||
DatabaseCleaner.clean
|
||||
UserFixer.load_user_fixtures
|
||||
Notifier.stub!(:send_request_accepted!).and_return(true)
|
||||
|
|
|
|||
Loading…
Reference in a new issue