fix(delayed): fix code style error

This commit is contained in:
lafirest 2022-03-11 11:32:25 +08:00
parent eeb92dae23
commit 1a8288de75
1 changed files with 7 additions and 5 deletions

View File

@ -55,6 +55,7 @@
-export([format_delayed/1]).
-record(delayed_message, {key, delayed, msg}).
-type delayed_message() :: #delayed_message{}.
%% sync ms with record change
-define(QUERY_MS(Id), [{{delayed_message, {'_', Id}, '_', '_'}, [], ['$_']}]).
@ -116,7 +117,7 @@ start_link() ->
Opts = emqx_conf:get([delayed], #{}),
gen_server:start_link({local, ?SERVER}, ?MODULE, [Opts], []).
-spec(store(#delayed_message{}) -> ok | {error, atom()}).
-spec(store(delayed_message()) -> ok | {error, atom()}).
store(DelayedMsg) ->
gen_server:call(?SERVER, {store, DelayedMsg}, infinity).
@ -273,14 +274,15 @@ handle_info({timeout, TRef, do_publish}, State = #{timer := TRef}) ->
{noreply, ensure_publish_timer(State#{timer := undefined, publish_at := 0})};
handle_info(stats, State = #{stats_fun := StatsFun}) ->
StatsTimer = erlang:send_after(timer:seconds(1), self(), stats),
StatsFun(delayed_count()),
{noreply, State, hibernate};
{noreply, State#{stats_timer := StatsTimer}, hibernate};
handle_info(Info, State) ->
?SLOG(error, #{msg => "unexpected_info", info => Info}),
{noreply, State}.
terminate(_Reason, #{timer := TRef}) ->
terminate(_Reason, #{stats_timer := TRef}) ->
emqx_conf:remove_handler([delayed]),
emqx_misc:cancel_timer(TRef).
@ -294,7 +296,7 @@ code_change(_Vsn, State, _Extra) ->
%% Ensure the stats
ensure_stats_event(State) ->
StatsFun = emqx_stats:statsfun('delayed.count', 'delayed.max'),
{ok, StatsTimer} = timer:send_interval(timer:seconds(1), stats),
StatsTimer = erlang:send_after(timer:seconds(1), self(), stats),
State#{stats_fun => StatsFun, stats_timer => StatsTimer}.
%% Ensure publish timer
@ -331,7 +333,7 @@ do_publish(Key = {Ts, _Id}, Now, Acc) when Ts =< Now ->
[#delayed_message{msg = Msg}] ->
emqx_pool:async_submit(fun emqx:publish/1, [Msg])
end,
do_publish(mnesia:dirty_next(?TAB, Key), Now, [Key|Acc]).
do_publish(mnesia:dirty_next(?TAB, Key), Now, [Key | Acc]).
-spec(delayed_count() -> non_neg_integer()).
delayed_count() -> mnesia:table_info(?TAB, size).