<commit_before>class RegistryHandler < ErrorsApi
  
   def initialize(system_api)
     @system_api = system_api     
   end
   
   # FIXME: take out or get_registry ip ..
   def start
     get_registry_ip
   end
   
  def force_registry_restart
      # start in thread in case timeout clobbers
      registry_service = test_system_api_result(@system_api.loadSystemService('registry'))
      # FIXME: need to panic if cannot load
      restart_thread = Thread.new {
        registry_service.stop_container
        registry_service.start_container
        while registry_service.is_startup_complete? == false
          sleep 1
          wait += 1
          return force_recreate if wait > 60
        end
      }
      restart_thread.join
      return true
    rescue StandardError => e
      @last_error = 'Fatal Unable to Start Registry Service: ' + e.to_s
      log_exception(e)
    end
  
    def get_registry_ip
      registry_service = test_system_api_result(@system_api.loadSystemService('registry'))
      case registry_service.read_state
      when 'nocontainer'
        registry_service.create_container
      when 'paused'
        registry_service.unpause_container
      when 'stopped'
        registry_service.start_container
      end
      if registry_service.read_state != 'running'
        if !force_recreate
          @last_error = 'Fatal Unable to Start Registry Service: ' + registry_service.last_error
          return nil
        end
      end
      wait = 0
      while !registry_service.is_startup_complete?
        sleep 1
        wait += 1
        break if wait > 60
      end
      return registry_service.get_ip_str
    rescue StandardError => e
      @last_error = 'Fatal Unable to Start Registry Service: ' + e.to_s
      log_exception(e)
    end   
    
  def test_system_api_result(result)
    @last_error = @system_api.last_error.to_s if result.nil? || result.is_a?(FalseClass)
    return result
  end
    
    private
    
  def force_recreate
     registry_service = test_system_api_result(@system_api.loadSystemService('registry'))
     return log_error_mesg('Fatal Unable to Start Registry Service: ',registry_service.last_error ) if !registry_service.forced_recreate
     return true
   end
end<commit_msg>log restarts and recreate of reg<commit_after>class RegistryHandler < ErrorsApi
  
   def initialize(system_api)
     @system_api = system_api     
   end
   
   # FIXME: take out or get_registry ip ..
   def start
     get_registry_ip
   end
   
  def force_registry_restart
      # start in thread in case timeout clobbers
    log_error_mesg("Forcing registry restart",nil)
      registry_service = test_system_api_result(@system_api.loadSystemService('registry'))
      # FIXME: need to panic if cannot load
      restart_thread = Thread.new {
        registry_service.stop_container
        registry_service.start_container
        while registry_service.is_startup_complete? == false
          sleep 1
          wait += 1
          return force_recreate if wait > 60
        end
      }
      restart_thread.join
      return true
    rescue StandardError => e
      @last_error = 'Fatal Unable to Start Registry Service: ' + e.to_s
      log_exception(e)
    end
  
    def get_registry_ip
      registry_service = test_system_api_result(@system_api.loadSystemService('registry'))
      case registry_service.read_state
      when 'nocontainer'
        registry_service.create_container
      when 'paused'
        registry_service.unpause_container
      when 'stopped'
        registry_service.start_container
      end
      if registry_service.read_state != 'running'
        if !force_recreate
          @last_error = 'Fatal Unable to Start Registry Service: ' + registry_service.last_error
          return nil
        end
      end
      wait = 0
      while !registry_service.is_startup_complete?
        sleep 1
        wait += 1
        break if wait > 60
      end
      return registry_service.get_ip_str
    rescue StandardError => e
      @last_error = 'Fatal Unable to Start Registry Service: ' + e.to_s
      log_exception(e)
    end   
    
  def test_system_api_result(result)
    @last_error = @system_api.last_error.to_s if result.nil? || result.is_a?(FalseClass)
    return result
  end
    
    private
    
  def force_recreate
    log_error_mesg("Forcing registry recreate", nil)
     registry_service = test_system_api_result(@system_api.loadSystemService('registry'))
     return log_error_mesg('Fatal Unable to Start Registry Service: ',registry_service.last_error ) if !registry_service.forced_recreate
     return true
   end
end
{'fraction_non_alphanumeric': 0.05993485342019544, 'fraction_numerical': 0.003908794788273616, 'mean_word_length': 2.646872525732383, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1449996', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1318, 'n_words': 331}