Clean up code
This commit is contained in:
parent
e61f75d86f
commit
a17857576d
|
@ -23,11 +23,8 @@ defmodule Chronoscope.NTS do
|
||||||
name = client_name(%{host: host, port: port})
|
name = client_name(%{host: host, port: port})
|
||||||
|
|
||||||
case Registry.lookup(NTS.Registry, name) do
|
case Registry.lookup(NTS.Registry, name) do
|
||||||
[{pid, _}] ->
|
[{pid, _}] -> GenServer.call(pid, :terminate)
|
||||||
GenServer.call(pid, :terminate)
|
[] -> {:error, :notfound}
|
||||||
|
|
||||||
[] ->
|
|
||||||
{:error, :notfound}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,9 +48,9 @@ defmodule Chronoscope.NTS do
|
||||||
"#{host}:#{port}"
|
"#{host}:#{port}"
|
||||||
end
|
end
|
||||||
|
|
||||||
defp start_client(%{host: host, port: port}, name) do
|
defp start_client(server, name) do
|
||||||
NTS.DynamicSupervisor
|
NTS.DynamicSupervisor
|
||||||
|> DynamicSupervisor.start_child({NTS.Client, host: host, port: port, name: {:via, Registry, {NTS.Registry, name}}})
|
|> DynamicSupervisor.start_child({NTS.Client, server: server, name: {:via, Registry, {NTS.Registry, name}}})
|
||||||
|> then(fn {:ok, pid} -> pid end)
|
|> then(fn {:ok, pid} -> pid end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,8 +6,8 @@ defmodule Chronoscope.NTS.Client do
|
||||||
|
|
||||||
@interval_in_seconds 30
|
@interval_in_seconds 30
|
||||||
|
|
||||||
def start_link(host: host, port: port, name: name) do
|
def start_link(server: server, name: name) do
|
||||||
GenServer.start_link(__MODULE__, %{host: host, port: port}, name: name)
|
GenServer.start_link(__MODULE__, server, name: name)
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
Loading…
Reference in New Issue