Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ExternalResource
module ExternalResource
# TODO: handle: Timeout::Error (time's up!):
# Requires a block with the HTTPClient.get call or what-have-you
# see InvitationRequestsController for details
def self.load( name = "" )
retries = 12
total = retries
puts "Started ExternalResource load call to: #{name}"
Rails.logger.info( "Started ExternalResource load call" )
begin
r = SystemTimer.timeout_after( 20 ) do
yield
end
return r
rescue Timeout::Error
Rails.logger.info( "Hit elusive 'Time's up!' error" )
puts "Hit elusive 'Time's up!' error"
retries -= 1
sleep 0.5 and retry
rescue => e
retries -= 1
Rails.logger.info( "Working on retry ##{retries} of #{total}" )
puts "Working on retry ##{retries} of #{total}"
Rails.logger.info( e )
puts e
if retries > 0
sleep 0.5 and retry
else
Rails.logger.error( "ERROR: Unable to receive or push external resource : #{e}" )
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment