Skip to content

Commit

Permalink
Adjusting backfill to be compatible with multiple ruby versions
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly committed Feb 2, 2017
1 parent cc28384 commit 3a7793c
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions lib/netsuite/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,32 @@ def backoff(options = {})
begin
count += 1
yield
rescue Errno::ECONNRESET,
Errno::ETIMEDOUT,
Errno::EHOSTUNREACH,
Net::ReadTimeout,
EOFError,
OpenSSL::SSL::SSLErrorWaitReadable,
Wasabi::Resolver::HTTPError,
Savon::SOAPFault,
Savon::InvalidResponseError,
Zlib::BufError,
Savon::HTTPError => e
rescue Exception => e
exceptions_to_retry = [
Errno::ECONNRESET,
Errno::ETIMEDOUT,
Errno::EHOSTUNREACH,
EOFError,
Wasabi::Resolver::HTTPError,
Savon::SOAPFault,
Savon::InvalidResponseError,
Zlib::BufError,
Savon::HTTPError
]

# available in ruby > 1.9
if defined?(Net::ReadTimeout)
exceptions_to_retry << Net::ReadTimeout
end

# available in ruby > 2.2.0
if defined?(OpenSSL::SSL::SSLErrorWaitReadable)
exceptions_to_retry << OpenSSL::SSL::SSLErrorWaitReadable
end

if !exceptions_to_retry.include?(e.class)
raise
end

# whitelist certain SOAPFaults; all other network errors should automatically retry
if e.is_a?(Savon::SOAPFault)
Expand All @@ -65,15 +80,17 @@ def backoff(options = {})
!e.message.include?('The Connection Pool is not intialized.') &&
# it looks like NetSuite mispelled their error message...
!e.message.include?('The Connection Pool is not intiialized.')
raise e
raise
end
end

if count >= (options[:attempts] || 8)
raise e
if count >= options[:attempts]
raise
end

# log.warn("concurrent request failure", sleep: count, attempt: count)
sleep(count)

retry
end
end
Expand Down

0 comments on commit 3a7793c

Please sign in to comment.