diff options
Diffstat (limited to 'lib/quiet_opener.rb')
-rw-r--r-- | lib/quiet_opener.rb | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb index a077ca323..8cedad250 100644 --- a/lib/quiet_opener.rb +++ b/lib/quiet_opener.rb @@ -1,11 +1,12 @@ require 'open-uri' require 'net-purge' +require 'net/http/local' def quietly_try_to_open(url) begin result = open(url).read.strip rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH - logger.warn("Unable to open third-party URL #{url}") + Rails.logger.warn("Unable to open third-party URL #{url}") result = "" end return result @@ -15,19 +16,21 @@ def quietly_try_to_purge(host, url) begin result = "" result_body = "" - Net::HTTP.start(host) {|http| - request = Net::HTTP::Purge.new(url) - response = http.request(request) - result = response.code - result_body = response.body - } + Net::HTTP.bind '127.0.0.1' do + Net::HTTP.start(host) {|http| + request = Net::HTTP::Purge.new(url) + response = http.request(request) + result = response.code + result_body = response.body + } + end rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH - logger.warn("Unable to reach host #{host}") + Rails.logger.warn("PURGE: Unable to reach host #{host}") end if result == "200" - logger.info("Purged URL #{url} at #{host}: #{result}") + Rails.logger.debug("PURGE: Purged URL #{url} at #{host}: #{result}") else - logger.warn("Unable to purge URL #{url} at #{host}: status #{result}") + Rails.logger.warn("PURGE: Unable to purge URL #{url} at #{host}: status #{result}") end return result end |