dotfiles/app/lib/prymn/agents.ex

20 lines
642 B
Elixir
Raw Normal View History

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