Sha256: ceb7b31d6236d047dc828ce78fd41027336e7013a10f0f886c70566c54ba951c
Contents?: true
Size: 1.44 KB
Versions: 11
Compression:
Stored size: 1.44 KB
Contents
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true module Contrast module Api # Keeps track of the state of connections to the service. class ConnectionStatus def initialize @last_success = nil @last_failure = nil @startup_messages_sent = false end # Whether we have sent startup message to the service. True after successfully # sending startup messages to service and reset to false if we lose connection # to the service. def startup_messages_sent? @startup_messages_sent end # A message was successfully sent to the service at some point def was_connected? @last_success end # The last message sent was successful def connected? @last_success && (@last_failure.nil? || @last_success > @last_failure) end # The last message sent was unsuccessful def failed? @last_failure && (@last_success.nil? || @last_failure > @last_success) end # The current state of the service is active with a successful message sent def success! @startup_messages_sent = true @last_success = Time.now.to_f end # The service may be in some sort of error state def failure! @startup_messages_sent = false @last_failure = Time.now.to_f end end end end
Version data entries
11 entries across 11 versions & 1 rubygems