Merge pull request #4070 from wwhai/fix-update-problem
feat(rule-engine): change init resource to test resource
This commit is contained in:
commit
001a89a396
|
@ -289,15 +289,20 @@ do_update_resource_check(Id, NewParams) ->
|
|||
do_update_resource(#{id := Id, type := Type, description:= NewDescription, config:= NewConfig}) ->
|
||||
case emqx_rule_registry:find_resource_type(Type) of
|
||||
{ok, #resource_type{on_create = {Module, Create},
|
||||
on_destroy = {Module, Destroy},
|
||||
params_spec = ParamSpec}} ->
|
||||
Config = emqx_rule_validator:validate_params(NewConfig, ParamSpec),
|
||||
cluster_call(init_resource, [Module, Create, Id, Config]),
|
||||
emqx_rule_registry:add_resource(#resource{id = Id,
|
||||
case test_resource(#{type => Type, config => NewConfig}) of
|
||||
ok ->
|
||||
Resource = #resource{id = Id,
|
||||
type = Type,
|
||||
config = Config,
|
||||
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.
|
||||
|
||||
-spec(start_resource(resource_id()) -> ok | {error, Reason :: term()}).
|
||||
|
|
|
@ -167,7 +167,7 @@ resources(["create" | Params]) ->
|
|||
|
||||
resources(["update" | Params]) ->
|
||||
with_opts(fun({Opts, _}) ->
|
||||
Id = maps:get(id, maps:from_list(Opts)),
|
||||
Id = proplists:get_value(id, Opts),
|
||||
Maps = make_updated_resource(Opts),
|
||||
case emqx_rule_engine:update_resource(Id, Maps) of
|
||||
ok ->
|
||||
|
|
Loading…
Reference in New Issue