Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block on startup while attempting first load #20

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
block on startup while attempting first load
sneako committed Sep 25, 2019
commit bcabb9229b8a373781057971693df65b58c393e1
25 changes: 13 additions & 12 deletions lib/strategy/tags.ex
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ defmodule ClusterEC2.Strategy.Tags do
def init([%State{} = state]) do
state = state |> Map.put(:meta, MapSet.new())

{:ok, state, 0}
{:ok, load(state)}
end

# libcluster ~> 2.0
@@ -64,18 +64,23 @@ defmodule ClusterEC2.Strategy.Tags do
meta: MapSet.new([])
}

{:ok, state, 0}
{:ok, load(state)}
end

@impl GenServer
def handle_info(:timeout, state) do
handle_info(:load, state)
end

def handle_info(
:load,
%State{topology: topology, connect: connect, disconnect: disconnect, list_nodes: list_nodes} = state
) do
def handle_info(:load, %State{} = state) do
{:noreply, load(state)}
end

def handle_info(_, state) do
{:noreply, state}
end

defp load(%State{topology: topology, connect: connect, disconnect: disconnect, list_nodes: list_nodes} = state) do
case get_nodes(state) do
{:ok, new_nodelist} ->
added = MapSet.difference(new_nodelist, state.meta)
@@ -106,18 +111,14 @@ defmodule ClusterEC2.Strategy.Tags do
end

Process.send_after(self(), :load, Keyword.get(state.config, :polling_interval, @default_polling_interval))
{:noreply, %{state | :meta => new_nodelist}}
%{state | :meta => new_nodelist}

_ ->
Process.send_after(self(), :load, Keyword.get(state.config, :polling_interval, @default_polling_interval))
{:noreply, state}
state
end
end

def handle_info(_, state) do
{:noreply, state}
end

@spec get_nodes(State.t()) :: {:ok, [atom()]} | {:error, []}
defp get_nodes(%State{topology: topology, config: config}) do
instance_id = ClusterEC2.local_instance_id()