fix(bridge): create bridge failed but the config was saved

This commit is contained in:
Shawn 2021-12-18 11:19:22 +08:00
parent 20091f8d2a
commit f08f37ec9c
1 changed files with 8 additions and 2 deletions

View File

@ -111,13 +111,15 @@ bridge_type(emqx_connector_http) -> http.
post_config_update(_, _Req, NewConf, OldConf, _AppEnv) ->
#{added := Added, removed := Removed, changed := Updated}
= diff_confs(NewConf, OldConf),
_ = perform_bridge_changes([
%% The config update will be failed if any task in `perform_bridge_changes` failed.
Result = perform_bridge_changes([
{fun remove/3, Removed},
{fun create/3, Added},
{fun update/3, Updated}
]),
ok = unload_hook(),
ok = load_hook(NewConf).
ok = load_hook(NewConf),
Result.
perform_bridge_changes(Tasks) ->
perform_bridge_changes(Tasks, ok).
@ -214,6 +216,10 @@ update(Type, Name, {_OldConf, Conf}) ->
config => Conf}),
case recreate(Type, Name, Conf) of
{ok, _} -> maybe_disable_bridge(Type, Name, Conf);
{error, not_found} ->
?SLOG(warning, #{ msg => "updating a non-exist bridge, create a new one"
, type => Type, name => Name, config => Conf}),
create(Type, Name, Conf);
{error, _} = Err -> Err
end.