fix(rule_engine): update status to false when refresh resource failed (#4821)

* fix(rule_engine): update status to false when refresh resource failed

* fix(dialyzer): ignore import_modules/1 created fun has no local return

* fix(appup): update appup for rule engine
This commit is contained in:
Shawn 2021-05-17 17:59:01 +08:00 committed by GitHub
parent 18036fdf3b
commit 4cd056cab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 23 deletions

View File

@ -503,6 +503,7 @@ do_import_acl_mnesia(Acls) ->
end.
-ifdef(EMQX_ENTERPRISE).
-dialyzer({nowarn_function, [import_modules/1]}).
import_modules(Modules) ->
case ets:info(emqx_modules) of
undefined ->

View File

@ -1,6 +1,6 @@
{application, emqx_rule_engine,
[{description, "EMQ X Rule Engine"},
{vsn, "4.3.1"}, % strict semver, bump manually!
{vsn, "4.3.2"}, % strict semver, bump manually!
{modules, []},
{registered, [emqx_rule_engine_sup, emqx_rule_registry]},
{applications, [kernel,stdlib,rulesql,getopt]},

View File

@ -1,13 +1,21 @@
%% -*-: erlang -*-
{"4.3.1",
{"4.3.2",
[ {"4.3.0",
[ {load_module, emqx_rule_funcs, brutal_purge, soft_purge, []}
[ {load_module, emqx_rule_funcs, brutal_purge, soft_purge, []},
{load_module, emqx_rule_engine, brutal_purge, soft_purge, []}
]},
{"4.3.1",
[ {load_module, emqx_rule_engine, brutal_purge, soft_purge, []}
]},
{<<".*">>, []}
],
[
{"4.3.0",
[ {load_module, emqx_rule_funcs, brutal_purge, soft_purge, []}
[ {load_module, emqx_rule_funcs, brutal_purge, soft_purge, []},
{load_module, emqx_rule_engine, brutal_purge, soft_purge, []}
]},
{"4.3.1",
[ {load_module, emqx_rule_engine, brutal_purge, soft_purge, []}
]},
{<<".*">>, []}
]

View File

@ -408,7 +408,7 @@ refresh_resource_status() ->
fun(#resource{id = ResId, type = ResType}) ->
case emqx_rule_registry:find_resource_type(ResType) of
{ok, #resource_type{on_status = {Mod, OnStatus}}} ->
fetch_resource_status(Mod, OnStatus, ResId);
_ = fetch_resource_status(Mod, OnStatus, ResId);
_ -> ok
end
end, emqx_rule_registry:get_resources()).
@ -588,27 +588,26 @@ clear_action(Module, Destroy, ActionInstId) ->
fetch_resource_status(Module, OnStatus, ResId) ->
case emqx_rule_registry:find_resource_params(ResId) of
{ok, ResParams = #resource_params{params = Params, status = #{is_alive := LastIsAlive}}} ->
try
NewStatus =
case Module:OnStatus(ResId, Params) of
#{is_alive := LastIsAlive} = Status -> Status;
#{is_alive := true} = Status ->
{ok, Type} = find_type(ResId),
Name = alarm_name_of_resource_down(Type, ResId),
emqx_alarm:deactivate(Name),
Status;
#{is_alive := false} = Status ->
{ok, Type} = find_type(ResId),
Name = alarm_name_of_resource_down(Type, ResId),
emqx_alarm:activate(Name, #{id => ResId, type => Type}),
Status
end,
emqx_rule_registry:add_resource_params(ResParams#resource_params{status = NewStatus}),
NewStatus
NewStatus = try
case Module:OnStatus(ResId, Params) of
#{is_alive := LastIsAlive} = Status -> Status;
#{is_alive := true} = Status ->
{ok, Type} = find_type(ResId),
Name = alarm_name_of_resource_down(Type, ResId),
emqx_alarm:deactivate(Name),
Status;
#{is_alive := false} = Status ->
{ok, Type} = find_type(ResId),
Name = alarm_name_of_resource_down(Type, ResId),
emqx_alarm:activate(Name, #{id => ResId, type => Type}),
Status
end
catch _Error:Reason:STrace ->
?LOG(error, "get resource status for ~p failed: ~0p", [ResId, {Reason, STrace}]),
#{is_alive => false}
end;
end,
emqx_rule_registry:add_resource_params(ResParams#resource_params{status = NewStatus}),
NewStatus;
not_found ->
#{is_alive => false}
end.