refactor(emqx_config_handler): async remove
This commit is contained in:
parent
88d891a59a
commit
019b9d17f6
|
@ -557,8 +557,14 @@ handle_info(Info, State) ->
|
|||
{noreply, State}.
|
||||
|
||||
terminate(Reason, _State) ->
|
||||
?SLOG(error, #{msg => "emqx_authentication_terminating",
|
||||
reason => Reason}),
|
||||
case Reason of
|
||||
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.
|
||||
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
|
|
|
@ -221,12 +221,12 @@ convert_certs(CertsDir, NewConfig, OldConfig) ->
|
|||
OldSSLOpts = maps:get(<<"ssl">>, OldConfig, #{}),
|
||||
Diff = diff_certs(NewSSLOpts, OldSSLOpts),
|
||||
NSSLOpts = lists:foldl(fun({identical, K}, Acc) ->
|
||||
Acc#{K => maps:get(K, OldSSLOpts)};
|
||||
({_, K}, Acc) ->
|
||||
CertFile = generate_filename(CertsDir, K),
|
||||
ok = save_cert_to_file(CertFile, maps:get(K, NewSSLOpts)),
|
||||
Acc#{K => CertFile}
|
||||
end, NewSSLOpts, Diff),
|
||||
Acc#{K => maps:get(K, OldSSLOpts)};
|
||||
({_, K}, Acc) ->
|
||||
CertFile = generate_filename(CertsDir, K),
|
||||
ok = save_cert_to_file(CertFile, maps:get(K, NewSSLOpts)),
|
||||
Acc#{K => CertFile}
|
||||
end, NewSSLOpts, Diff),
|
||||
NewConfig#{<<"ssl">> => NSSLOpts}
|
||||
end.
|
||||
|
||||
|
|
|
@ -77,9 +77,10 @@ update_config(SchemaModule, ConfKeyPath, UpdateArgs) ->
|
|||
add_handler(ConfKeyPath, HandlerName) ->
|
||||
gen_server:call(?MODULE, {add_handler, ConfKeyPath, HandlerName}, infinity).
|
||||
|
||||
%% @doc Remove handler asynchronously
|
||||
-spec remove_handler(emqx_config:config_key_path()) -> ok.
|
||||
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}
|
||||
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,
|
||||
#{handlers := Handlers} = State) ->
|
||||
Reply = try
|
||||
|
@ -125,6 +121,9 @@ handle_call(_Request, _From, State) ->
|
|||
Reply = ok,
|
||||
{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) ->
|
||||
{noreply, State}.
|
||||
|
||||
|
|
Loading…
Reference in New Issue