Merge pull request #4070 from wwhai/fix-update-problem

feat(rule-engine): change init resource to test resource
This commit is contained in:
wwhai 2021-01-27 17:09:37 +08:00 committed by GitHub
commit 001a89a396
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 39 deletions

View File

@ -289,15 +289,20 @@ do_update_resource_check(Id, NewParams) ->
do_update_resource(#{id := Id, type := Type, description:= NewDescription, config:= NewConfig}) -> do_update_resource(#{id := Id, type := Type, description:= NewDescription, config:= NewConfig}) ->
case emqx_rule_registry:find_resource_type(Type) of case emqx_rule_registry:find_resource_type(Type) of
{ok, #resource_type{on_create = {Module, Create}, {ok, #resource_type{on_create = {Module, Create},
on_destroy = {Module, Destroy},
params_spec = ParamSpec}} -> params_spec = ParamSpec}} ->
Config = emqx_rule_validator:validate_params(NewConfig, ParamSpec), Config = emqx_rule_validator:validate_params(NewConfig, ParamSpec),
cluster_call(init_resource, [Module, Create, Id, Config]), case test_resource(#{type => Type, config => NewConfig}) of
emqx_rule_registry:add_resource(#resource{id = Id, ok ->
Resource = #resource{id = Id,
type = Type, type = Type,
config = Config, config = Config,
description = NewDescription, description = NewDescription,
created_at = erlang:system_time(millisecond)}) created_at = erlang:system_time(millisecond)},
cluster_call(init_resource, [Module, Create, Id, Config]),
emqx_rule_registry:add_resource(Resource);
{error, Reason} ->
{error, Reason}
end
end. end.
-spec(start_resource(resource_id()) -> ok | {error, Reason :: term()}). -spec(start_resource(resource_id()) -> ok | {error, Reason :: term()}).

View File

@ -167,7 +167,7 @@ resources(["create" | Params]) ->
resources(["update" | Params]) -> resources(["update" | Params]) ->
with_opts(fun({Opts, _}) -> with_opts(fun({Opts, _}) ->
Id = maps:get(id, maps:from_list(Opts)), Id = proplists:get_value(id, Opts),
Maps = make_updated_resource(Opts), Maps = make_updated_resource(Opts),
case emqx_rule_engine:update_resource(Id, Maps) of case emqx_rule_engine:update_resource(Id, Maps) of
ok -> ok ->