Sha256: 94d2e4dafd9305a486912574f98b00d545cc0003b5189df35f850e44334ac8cc

Contents?: true

Size: 1.31 KB

Versions: 20

Compression:

Stored size: 1.31 KB

Contents

# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

module Contrast
  module Api
    module Communication
      # Keeps track of the state of connections to SpeedRacer.
      class ConnectionStatus
        def initialize
          @last_success = nil
          @last_failure = nil
          @startup_messages_sent = false
        end

        # Whether we have sent startup message to SpeedRacer. True after successfully sending startup messages to
        # SpeedRacer and reset to false if we lose connection.
        #
        # @return [Boolean]
        def startup_messages_sent?
          @startup_messages_sent
        end

        # The last message sent was successful or not
        #
        # @return [Boolean]
        def connected?
          @last_success && (@last_failure.nil? || @last_success > @last_failure)
        end

        # The current state of the SpeedRacer is active with a successful message sent
        def success!
          @startup_messages_sent = true
          @last_success = Time.now.to_f
        end

        # The SpeedRacer may be in some sort of error state
        def failure!
          @startup_messages_sent = false
          @last_failure = Time.now.to_f
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
contrast-agent-6.7.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.6.5 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.6.4 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.6.3 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.6.2 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.6.1 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.6.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.5.1 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.5.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.4.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.3.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.2.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.1.2 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.1.1 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.1.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-6.0.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-5.3.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-5.2.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-5.1.0 lib/contrast/api/communication/connection_status.rb
contrast-agent-5.0.0 lib/contrast/api/communication/connection_status.rb