Merge pull request #7635 from terry-xiaoyu/test_resource_failed

fix(rule): test resource failed from all nodes
This commit is contained in:
Xinyu Liu 2022-04-16 02:18:44 +08:00 committed by GitHub
commit ade2716616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -39,6 +39,7 @@
, get_resource_status/1 , get_resource_status/1
, is_source_alive/1 , is_source_alive/1
, get_resource_params/1 , get_resource_params/1
, ensure_resource_deleted/1
, delete_resource/1 , delete_resource/1
, update_resource/2 , update_resource/2
]). ]).
@ -328,6 +329,7 @@ start_resource(ResId) ->
{error, {resource_not_found, ResId}} {error, {resource_not_found, ResId}}
end. end.
-dialyzer([{nowarn_function, test_resource/1}]).
-spec(test_resource(#{type := _, config := _, _ => _}) -> ok | {error, Reason :: term()}). -spec(test_resource(#{type := _, config := _, _ => _}) -> ok | {error, Reason :: term()}).
test_resource(#{type := Type} = Params) -> test_resource(#{type := Type} = Params) ->
case emqx_rule_registry:find_resource_type(Type) of case emqx_rule_registry:find_resource_type(Type) of
@ -353,7 +355,8 @@ test_resource(#{type := Type} = Params) ->
?LOG(warning, "test resource failed, ~0p:~0p ~0p", [E, R, S]), ?LOG(warning, "test resource failed, ~0p:~0p ~0p", [E, R, S]),
{error, R} {error, R}
after after
_ = ?CLUSTER_CALL(delete_resource, [ResId]) _ = ?CLUSTER_CALL(ensure_resource_deleted, [ResId]),
ok
end; end;
not_found -> not_found ->
{error, {resource_type_not_found, Type}} {error, {resource_type_not_found, Type}}
@ -390,6 +393,11 @@ get_resource_params(ResId) ->
{error, resource_not_initialized} {error, resource_not_initialized}
end. end.
-spec(ensure_resource_deleted(resource_id()) -> ok).
ensure_resource_deleted(ResId) ->
_ = delete_resource(ResId),
ok.
-spec(delete_resource(resource_id()) -> ok | {error, Reason :: term()}). -spec(delete_resource(resource_id()) -> ok | {error, Reason :: term()}).
delete_resource(ResId) -> delete_resource(ResId) ->
case emqx_rule_registry:find_resource(ResId) of case emqx_rule_registry:find_resource(ResId) of