Merge pull request #11640 from zhongwencool/ensure-destory-resource
fix: always return ok when remove local resource
This commit is contained in:
commit
123d31fa7d
|
@ -298,11 +298,7 @@ remove(Type, Name) ->
|
||||||
%% just for perform_bridge_changes/1
|
%% just for perform_bridge_changes/1
|
||||||
remove(Type, Name, _Conf, _Opts) ->
|
remove(Type, Name, _Conf, _Opts) ->
|
||||||
?SLOG(info, #{msg => "remove_bridge", type => Type, name => Name}),
|
?SLOG(info, #{msg => "remove_bridge", type => Type, name => Name}),
|
||||||
case emqx_resource:remove_local(resource_id(Type, Name)) of
|
emqx_resource:remove_local(resource_id(Type, Name)).
|
||||||
ok -> ok;
|
|
||||||
{error, not_found} -> ok;
|
|
||||||
{error, Reason} -> {error, Reason}
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% convert bridge configs to what the connector modules want
|
%% convert bridge configs to what the connector modules want
|
||||||
parse_confs(
|
parse_confs(
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
-include("emqx_resource.hrl").
|
-include("emqx_resource.hrl").
|
||||||
-include("emqx_resource_utils.hrl").
|
-include("emqx_resource_utils.hrl").
|
||||||
-include("emqx_resource_errors.hrl").
|
-include("emqx_resource_errors.hrl").
|
||||||
|
-include_lib("emqx/include/logger.hrl").
|
||||||
|
|
||||||
%% APIs for resource types
|
%% APIs for resource types
|
||||||
|
|
||||||
|
@ -257,9 +258,23 @@ recreate_local(ResId, ResourceType, Config, Opts) ->
|
||||||
remove(ResId) ->
|
remove(ResId) ->
|
||||||
emqx_resource_proto_v1:remove(ResId).
|
emqx_resource_proto_v1:remove(ResId).
|
||||||
|
|
||||||
-spec remove_local(resource_id()) -> ok | {error, Reason :: term()}.
|
-spec remove_local(resource_id()) -> ok.
|
||||||
remove_local(ResId) ->
|
remove_local(ResId) ->
|
||||||
emqx_resource_manager:remove(ResId).
|
case emqx_resource_manager:remove(ResId) of
|
||||||
|
ok ->
|
||||||
|
ok;
|
||||||
|
{error, not_found} ->
|
||||||
|
ok;
|
||||||
|
Error ->
|
||||||
|
%% Only log, the ResId worker is always removed in manager's remove action.
|
||||||
|
?SLOG(warning, #{
|
||||||
|
msg => "remove_local_resource_failed",
|
||||||
|
error => Error,
|
||||||
|
resource_id => ResId
|
||||||
|
}),
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
ok.
|
||||||
|
|
||||||
-spec reset_metrics_local(resource_id()) -> ok.
|
-spec reset_metrics_local(resource_id()) -> ok.
|
||||||
reset_metrics_local(ResId) ->
|
reset_metrics_local(ResId) ->
|
||||||
|
|
|
@ -110,7 +110,7 @@ t_create_remove(_) ->
|
||||||
?assert(is_process_alive(Pid)),
|
?assert(is_process_alive(Pid)),
|
||||||
|
|
||||||
?assertEqual(ok, emqx_resource:remove(?ID)),
|
?assertEqual(ok, emqx_resource:remove(?ID)),
|
||||||
?assertMatch({error, _}, emqx_resource:remove(?ID)),
|
?assertMatch(ok, emqx_resource:remove(?ID)),
|
||||||
|
|
||||||
?assertNot(is_process_alive(Pid))
|
?assertNot(is_process_alive(Pid))
|
||||||
end,
|
end,
|
||||||
|
@ -164,7 +164,7 @@ t_create_remove_local(_) ->
|
||||||
),
|
),
|
||||||
|
|
||||||
?assertEqual(ok, emqx_resource:remove_local(?ID)),
|
?assertEqual(ok, emqx_resource:remove_local(?ID)),
|
||||||
?assertMatch({error, _}, emqx_resource:remove_local(?ID)),
|
?assertMatch(ok, emqx_resource:remove_local(?ID)),
|
||||||
|
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
?RESOURCE_ERROR(not_found),
|
?RESOURCE_ERROR(not_found),
|
||||||
|
|
Loading…
Reference in New Issue