refactor(emqx_config_handler): async remove
This commit is contained in:
parent
6d9b3ed341
commit
c0364ad5a2
|
@ -557,8 +557,14 @@ handle_info(Info, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
terminate(Reason, _State) ->
|
terminate(Reason, _State) ->
|
||||||
?SLOG(error, #{msg => "emqx_authentication_terminating",
|
case Reason of
|
||||||
reason => Reason}),
|
normal -> ok;
|
||||||
|
{shutdown, _} -> ok;
|
||||||
|
Other -> ?SLOG(error, #{msg => "emqx_authentication_terminating",
|
||||||
|
reason => Other})
|
||||||
|
end,
|
||||||
|
emqx_config_handler:remove_handler([authentication]),
|
||||||
|
emqx_config_handler:remove_handler([listeners, '?', '?', authentication]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
code_change(_OldVsn, State, _Extra) ->
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
|
|
|
@ -221,12 +221,12 @@ convert_certs(CertsDir, NewConfig, OldConfig) ->
|
||||||
OldSSLOpts = maps:get(<<"ssl">>, OldConfig, #{}),
|
OldSSLOpts = maps:get(<<"ssl">>, OldConfig, #{}),
|
||||||
Diff = diff_certs(NewSSLOpts, OldSSLOpts),
|
Diff = diff_certs(NewSSLOpts, OldSSLOpts),
|
||||||
NSSLOpts = lists:foldl(fun({identical, K}, Acc) ->
|
NSSLOpts = lists:foldl(fun({identical, K}, Acc) ->
|
||||||
Acc#{K => maps:get(K, OldSSLOpts)};
|
Acc#{K => maps:get(K, OldSSLOpts)};
|
||||||
({_, K}, Acc) ->
|
({_, K}, Acc) ->
|
||||||
CertFile = generate_filename(CertsDir, K),
|
CertFile = generate_filename(CertsDir, K),
|
||||||
ok = save_cert_to_file(CertFile, maps:get(K, NewSSLOpts)),
|
ok = save_cert_to_file(CertFile, maps:get(K, NewSSLOpts)),
|
||||||
Acc#{K => CertFile}
|
Acc#{K => CertFile}
|
||||||
end, NewSSLOpts, Diff),
|
end, NewSSLOpts, Diff),
|
||||||
NewConfig#{<<"ssl">> => NSSLOpts}
|
NewConfig#{<<"ssl">> => NSSLOpts}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -77,9 +77,10 @@ update_config(SchemaModule, ConfKeyPath, UpdateArgs) ->
|
||||||
add_handler(ConfKeyPath, HandlerName) ->
|
add_handler(ConfKeyPath, HandlerName) ->
|
||||||
gen_server:call(?MODULE, {add_handler, ConfKeyPath, HandlerName}, infinity).
|
gen_server:call(?MODULE, {add_handler, ConfKeyPath, HandlerName}, infinity).
|
||||||
|
|
||||||
|
%% @doc Remove handler asynchronously
|
||||||
-spec remove_handler(emqx_config:config_key_path()) -> ok.
|
-spec remove_handler(emqx_config:config_key_path()) -> ok.
|
||||||
remove_handler(ConfKeyPath) ->
|
remove_handler(ConfKeyPath) ->
|
||||||
gen_server:call(?MODULE, {remove_handler, ConfKeyPath}, infinity).
|
gen_server:cast(?MODULE, {remove_handler, ConfKeyPath}).
|
||||||
|
|
||||||
%%============================================================================
|
%%============================================================================
|
||||||
|
|
||||||
|
@ -95,11 +96,6 @@ handle_call({add_handler, ConfKeyPath, HandlerName}, _From, State = #{handlers :
|
||||||
{reply, Error, State}
|
{reply, Error, State}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
handle_call({remove_handler, ConfKeyPath}, _From,
|
|
||||||
State = #{handlers := Handlers}) ->
|
|
||||||
{reply, ok, State#{handlers =>
|
|
||||||
emqx_map_lib:deep_remove(ConfKeyPath ++ [?MOD], Handlers)}};
|
|
||||||
|
|
||||||
handle_call({change_config, SchemaModule, ConfKeyPath, UpdateArgs}, _From,
|
handle_call({change_config, SchemaModule, ConfKeyPath, UpdateArgs}, _From,
|
||||||
#{handlers := Handlers} = State) ->
|
#{handlers := Handlers} = State) ->
|
||||||
Reply = try
|
Reply = try
|
||||||
|
@ -125,6 +121,9 @@ handle_call(_Request, _From, State) ->
|
||||||
Reply = ok,
|
Reply = ok,
|
||||||
{reply, Reply, State}.
|
{reply, Reply, State}.
|
||||||
|
|
||||||
|
handle_cast({remove_handler, ConfKeyPath},
|
||||||
|
State = #{handlers := Handlers}) ->
|
||||||
|
{noreply, State#{handlers => emqx_map_lib:deep_remove(ConfKeyPath ++ [?MOD], Handlers)}};
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue