feat(rule-engine): change init resource to test resource
This commit is contained in:
parent
6a6a94f99e
commit
81da182e1b
|
@ -288,16 +288,19 @@ 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{params_spec = ParamSpec}} ->
|
||||||
on_destroy = {Module, Destroy},
|
|
||||||
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)},
|
||||||
|
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()}).
|
||||||
|
|
|
@ -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 ->
|
||||||
|
|
Loading…
Reference in New Issue