Skip to content

Commit

Permalink
KAZOO-717: fix typo, use reference to track current timer message, an…
Browse files Browse the repository at this point in the history
…d ensure when reconnecting/disconnecting timers have no way to stack
  • Loading branch information
k-anderson committed Mar 16, 2013
1 parent e2c0ed6 commit e5afe8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/whistle-1.0.0/src/wh_nodes.erl
Expand Up @@ -39,13 +39,13 @@
-define(QUEUE_OPTIONS, []).
-define(CONSUME_OPTIONS, []).

-define(HEARTBEAT, 2000).
-define(HEARTBEAT, 5000).
-define(EXPIRE_PERIOD, 1000).
-define(FUDGE_FACTOR, 1.25).
-define(APP_NAME, <<"wh_nodes">>).
-define(APP_VERSION, <<"0.1.0">>).

-record(state, {heartbeat_tref :: 'undefined' | timer:ref()
-record(state, {heartbeat_ref :: 'undefined' | reference()
,tab
,notify_new = sets:new() :: set()
,notify_expire = sets:new() :: set()
Expand Down Expand Up @@ -206,11 +206,10 @@ handle_cast({'advertise', JObj}, #state{tab=Tab}=State) ->
'false' -> ets:insert(Tab, Node)
end,
{noreply, State};
handle_cast({'wh_amqp_channel', {'new_channel', _}}, #state{heartbeat_tref=TRef}=State) ->
timer:cancel(TRef),
self() ! 'hearbeat',
Heartbeat = timer:send_interval(?HEARTBEAT, 'hearbeat'),
{noreply, State#state{heartbeat_tref=Heartbeat}};
handle_cast({'wh_amqp_channel', {'new_channel', _}}, State) ->
Reference = erlang:make_ref(),
self() ! {'heartbeat', Reference},
{noreply, State#state{heartbeat_ref=Reference}};
handle_cast(_Msg, State) ->
{noreply, State}.

Expand All @@ -236,10 +235,12 @@ handle_info('expire_nodes', #state{tab=Tab}=State) ->
_ = spawn(fun() -> notify_expire(Nodes, State) end),
_ = erlang:send_after(?EXPIRE_PERIOD, self(), 'expire_nodes'),
{noreply, State};
handle_info('hearbeat', State) ->
handle_info({'heartbeat', Ref}, #state{heartbeat_ref=Ref}=State) ->
Node = create_node(),
wapi_nodes:publish_advertise(advertise_payload(Node)),
{noreply, State};
Reference = erlang:make_ref(),
_ = erlang:send_after(?HEARTBEAT, self(), {'heartbeat', Reference}),
{noreply, State#state{heartbeat_ref=Reference}};
handle_info({'DOWN', Ref, 'process', Pid, _}, #state{notify_new=NewSet
,notify_expire=ExpireSet}=State) ->
erlang:demonitor(Ref, ['flush']),
Expand Down
13 changes: 13 additions & 0 deletions lib/whistle-1.0.0/src/whistle_maintenance.erl
Expand Up @@ -9,6 +9,10 @@
-module(whistle_maintenance).

-export([nodes/0]).
-export([syslog_level/1
,error_level/1
,console_level/1
]).
-export([gc_all/0, gc_pids/1
,gc_top_mem_consumers/0, gc_top_mem_consumers/1
,top_mem_consumers/0, top_mem_consumers/1
Expand All @@ -27,6 +31,15 @@
-spec top_mem_consumers/1 :: (pos_integer()) -> {wh_proplist_kv(pid(), integer()), wh_proplist_kv(pid(), integer())}.
-spec etop/0 :: () -> 'ok'.

syslog_level(Level) ->
wh_util:change_syslog_log_level(wh_util:to_atom(Level)).

error_level(Level) ->
wh_util:change_error_log_level(wh_util:to_atom(Level)).

console_level(Level) ->
wh_util:change_console_log_level(wh_util:to_atom(Level)).

nodes() ->
wh_nodes:status().

Expand Down

0 comments on commit e5afe8f

Please sign in to comment.