Class: ForestAdminDatasourceRpc::Utils::SseClient
- Inherits:
-
Object
- Object
- ForestAdminDatasourceRpc::Utils::SseClient
- Defined in:
- lib/forest_admin_datasource_rpc/Utils/sse_client.rb
Constant Summary collapse
- MAX_BACKOFF_DELAY =
seconds
30- INITIAL_BACKOFF_DELAY =
seconds
2
Instance Attribute Summary collapse
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(uri, auth_secret, &on_rpc_stop) ⇒ SseClient
constructor
A new instance of SseClient.
- #start ⇒ Object
Constructor Details
#initialize(uri, auth_secret, &on_rpc_stop) ⇒ SseClient
Returns a new instance of SseClient.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/forest_admin_datasource_rpc/Utils/sse_client.rb', line 14 def initialize(uri, auth_secret, &on_rpc_stop) @uri = uri @auth_secret = auth_secret @on_rpc_stop = on_rpc_stop @client = nil @closed = false @connection_attempts = 0 @reconnect_thread = nil @connecting = false end |
Instance Attribute Details
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
9 10 11 |
# File 'lib/forest_admin_datasource_rpc/Utils/sse_client.rb', line 9 def closed @closed end |
Instance Method Details
#close ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/forest_admin_datasource_rpc/Utils/sse_client.rb', line 31 def close return if @closed @closed = true ForestAdminRpcAgent::Facades::Container.logger&.log('Debug', '[SSE Client] Closing connection') # Stop reconnection thread if running if @reconnect_thread&.alive? @reconnect_thread.kill @reconnect_thread = nil end begin @client&.close rescue StandardError => e ForestAdminRpcAgent::Facades::Container.logger&.log('Debug', "[SSE Client] Error during close: #{e.}") end ForestAdminRpcAgent::Facades::Container.logger&.log('Debug', '[SSE Client] Connection closed') end |
#start ⇒ Object
25 26 27 28 29 |
# File 'lib/forest_admin_datasource_rpc/Utils/sse_client.rb', line 25 def start return if @closed attempt_connection end |