Created
          November 24, 2011 18:18 
        
      - 
      
- 
        Save chuckbergeron/1391967 to your computer and use it in GitHub Desktop. 
    ExternalResource
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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