class Client
A client provides a mechanism to connect to a supervisor server in order to execute operations.
Definitions
def initialize(endpoint: Supervisor.endpoint)
Initialize a new client.
Signature
-
parameter
endpointIO::Endpoint The supervisor endpoint to connect to.
Implementation
def initialize(endpoint: Supervisor.endpoint)
@endpoint = endpoint
end
def connect
Connect to the server.
Implementation
def connect
connection = connect!
connection.run_in_background(self)
connected!(connection)
return connection unless block_given?
begin
yield connection
ensure
connection.close
end
end
def run
Run the client in a loop, reconnecting if necessary.
Implementation
def run
Async(annotation: "Supervisor Client", transient: true) do |task|
loop do
connection = connect!
connected_task = task.async do
connected!(connection)
end
connection.run(self)
rescue => error
Console.error(self, "Connection failed:", exception: error)
sleep(rand)
ensure
# Ensure any tasks that were created during connection are stopped:
connected_task&.stop
# Close the connection itself:
connection&.close
end
end
end