Class: Contrast::Api::Communication::ConnectionStatus
- Defined in:
- lib/contrast/api/communication/connection_status.rb
Overview
Keeps track of the state of connections to the service.
Instance Method Summary collapse
-
#connected? ⇒ Boolean
The last message sent was successful.
-
#failure! ⇒ Object
The service may be in some sort of error state.
-
#initialize ⇒ ConnectionStatus
constructor
A new instance of ConnectionStatus.
-
#startup_messages_sent? ⇒ Boolean
Whether we have sent startup message to the service.
-
#success! ⇒ Object
The current state of the service is active with a successful message sent.
Constructor Details
#initialize ⇒ ConnectionStatus
Returns a new instance of ConnectionStatus.
9 10 11 12 13 |
# File 'lib/contrast/api/communication/connection_status.rb', line 9 def initialize @last_success = nil @last_failure = nil @startup_messages_sent = false end |
Instance Method Details
#connected? ⇒ Boolean
The last message sent was successful
23 24 25 |
# File 'lib/contrast/api/communication/connection_status.rb', line 23 def connected? @last_success && (@last_failure.nil? || @last_success > @last_failure) end |
#failure! ⇒ Object
The service may be in some sort of error state
34 35 36 37 |
# File 'lib/contrast/api/communication/connection_status.rb', line 34 def failure! @startup_messages_sent = false @last_failure = Time.now.to_f end |
#startup_messages_sent? ⇒ Boolean
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.
18 19 20 |
# File 'lib/contrast/api/communication/connection_status.rb', line 18 def @startup_messages_sent end |
#success! ⇒ Object
The current state of the service is active with a successful message sent
28 29 30 31 |
# File 'lib/contrast/api/communication/connection_status.rb', line 28 def success! @startup_messages_sent = true @last_success = Time.now.to_f end |