`Prymn.Agent.Connection` GenServer uses healthchecking with the new streaming RPC, retrieving asynchronously the health status of the agent. The Connection will also shut itself down when there's no usage (when the keepalive function is not called frequently)
19 lines
642 B
Elixir
19 lines
642 B
Elixir
defmodule Prymn.Agents do
|
|
@moduledoc ~S"""
|
|
Prymn Agents are programs that manage a remote client machine. Prymn backend
|
|
communicates with them using GRPC calls. GRPC connections are started using
|
|
the Prymn.Agents.Supervisor (a DynamicSupervisor) and are book-kept using the
|
|
Prymn.Agents.Registry.
|
|
"""
|
|
|
|
def start_connection_or_keep_alive(ip) do
|
|
case Registry.lookup(Prymn.Agents.Registry, ip) do
|
|
[{pid, _}] ->
|
|
Prymn.Agents.Connection.keep_alive(pid)
|
|
|
|
[] ->
|
|
child = {Prymn.Agents.Connection, ip}
|
|
{:ok, _pid} = DynamicSupervisor.start_child(Prymn.Agents.Supervisor, child)
|
|
end
|
|
end
|
|
end
|