2023-06-27 19:28:00 +00:00
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2023-08-19 18:14:07 +00:00
|
|
|
def start_connection_or_keep_alive(ip) do
|
|
|
|
case Registry.lookup(Prymn.Agents.Registry, ip) do
|
|
|
|
[{pid, _}] ->
|
|
|
|
Prymn.Agents.Connection.keep_alive(pid)
|
2023-06-27 19:28:00 +00:00
|
|
|
|
2023-08-19 18:14:07 +00:00
|
|
|
[] ->
|
|
|
|
child = {Prymn.Agents.Connection, ip}
|
|
|
|
{:ok, _pid} = DynamicSupervisor.start_child(Prymn.Agents.Supervisor, child)
|
2023-06-27 19:28:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|