Skip to content

Instantly share code, notes, and snippets.

@tuulos
Created July 21, 2010 02:43
Show Gist options
  • Save tuulos/483964 to your computer and use it in GitHub Desktop.
Save tuulos/483964 to your computer and use it in GitHub Desktop.
handle_cast({update_config_table, Config}, S) ->
error_logger:info_report([{"Config table update"}]),
Update = fun({Host, Slots}, DNodes) ->
DNode = case gb_trees:lookup(Host, S#state.nodes) of
none ->
#dnode{name = Host,
slots = Slots,
node_mon = monitor(Host)};
{value, N} ->
N#dnode{slots = Slots}
end,
gb_trees:insert(Host, DNode, DNodes)
end;
DNodes = lists:foldl(gb_trees:empty(), Update, Config),
lists:foreach(fun(DNode) ->
case gb_trees:lookup(DNode#dnode.name, DNodes) of
none ->
unlink(DNode#dnode.node_mon),
exit(DNode#dnode.node_mon, kill);
_ -> ok
end
end, gb_trees:values(S#state.nodes)),
disco_proxy:update_nodes(gb_trees:keys(DNodes)),
update_nodes(DNodes),
{noreply, S#state{nodes = DNodes}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment