This commit is contained in:
Feng 2015-10-16 14:58:51 +08:00
parent 61a6818767
commit a35d51ea24
1 changed files with 7 additions and 2 deletions

View File

@ -25,6 +25,7 @@
%%% @end
%%%-----------------------------------------------------------------------------
%% TODO: should match topic tree
-module(emqttd_retained).
-author("Feng Lee <feng@emqtt.io>").
@ -150,9 +151,9 @@ dispatch(Topic, CPid) when is_binary(Topic) ->
init([]) ->
StatsFun = emqttd_stats:statsfun('retained/count', 'retained/max'),
%% One second
{ok, StatsTimer} = timer:send_interval(1000, stats),
{ok, StatsTimer} = timer:send_interval(timer:seconds(1), stats),
%% Five minutes
{ok, ExpireTimer} = timer:send_interval(300 * 1000, expire),
{ok, ExpireTimer} = timer:send_interval(timer:minutes(5), expire),
{ok, #state{stats_fun = StatsFun,
expired_after = env(expired_after),
stats_timer = StatsTimer,
@ -169,6 +170,10 @@ handle_info(stats, State = #state{stats_fun = StatsFun}) ->
StatsFun(mnesia:table_info(retained, size)),
{noreply, State, hibernate};
handle_info(expire, State = #state{expired_after = Never})
when Never =:= 0 orelse Never =:= undefined ->
{noreply, State, hibernate};
handle_info(expire, State = #state{expired_after = ExpiredAfter}) ->
expire(emqttd_util:now_to_secs(os:timestamp()) - ExpiredAfter),
{noreply, State, hibernate};