feat(rule-engine): change init resource to test resource

This commit is contained in:
wwhai 2021-01-25 19:43:44 +08:00
parent 6a6a94f99e
commit 81da182e1b
3 changed files with 44 additions and 41 deletions

View File

@ -288,16 +288,19 @@ 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}} ->
{ok, #resource_type{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)},
emqx_rule_registry:add_resource(Resource);
{error, Reason} ->
{error, Reason}
end
end.
-spec(start_resource(resource_id()) -> ok | {error, Reason :: term()}).

View File

@ -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 ->