run

in lib/instance_agent/agent/base.rb [23:63]


      def run
        start_time = Time.now

        begin
          perform
          @error_count = 0
        rescue Seahorse::Client::NetworkingError => e
          log(:error, "Network error: " + e.inspect)
          if e.message.include? "certificate verify failed"
            log(:error, "Failed to execute the command. Your certificates might have been deleted" )
          end
          @error_count = @error_count.to_i + 1
        rescue Aws::Errors::MissingCredentialsError
          log(:error, "Missing credentials - please check if this instance was started with an IAM instance profile")
          @error_count = @error_count.to_i + 1
        rescue SocketError, Errno::ENETDOWN, Aws::Errors::ServiceError => e
          log(:error, "Cannot reach InstanceService: #{e.class} - #{e.message}")
          @error_count = @error_count.to_i + 1
        rescue Exception => e
          log(:error, "Error during perform: #{e.class} - #{e.message} - #{e.backtrace.join("\n")}")
          @error_count = @error_count.to_i + 1
        end

        if @error_count > 0
          

          if @error_count > 10
            @error_count = 10
          end

          elapsed_time = (Time.now - start_time).ceil
          backoff_time = (((1.2675 ** @error_count) * (90.0 / (1.2675 ** 10)))).floor
          sleep_time = backoff_time - elapsed_time

          if(sleep_time > 0)
            log(:debug, "Sleeping #{sleep_time} seconds.")
            sleep sleep_time
          end
        end
      end