Current section

Files

Jump to
sailfish lib sailfish.ex
Raw

lib/sailfish.ex

defmodule Sailfish.Client do
use GenServer
require Logger
def start_link(opts) do
GenServer.start_link(__MODULE__, opts)
end
def init(opts) do
send(self(), :connect)
{:ok, Map.merge(%{}, opts)}
end
def handle_info(:connect, state) do
Logger.info("Sailfish attempting connection")
with {:ok, pid} <-
Riptide.Client.start_link(state.url, [Sailfish.Client.Commands.Console], name: Sailfish),
auth =
Map.merge(
%{
token: "unknown",
node: :inet.gethostname() |> elem(1) |> String.Chars.to_string(),
tags: %{}
},
state
),
{:ok, pid} <- Riptide.Client.call(Sailfish, "auth.node", auth) do
Logger.info("Sailfish authenticated")
else
_ -> Process.send_after(self(), :connect, :timer.seconds(5))
end
{:noreply, state}
end
end