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:
parent
18036fdf3b
commit
4cd056cab5
|
@ -503,6 +503,7 @@ do_import_acl_mnesia(Acls) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-ifdef(EMQX_ENTERPRISE).
|
-ifdef(EMQX_ENTERPRISE).
|
||||||
|
-dialyzer({nowarn_function, [import_modules/1]}).
|
||||||
import_modules(Modules) ->
|
import_modules(Modules) ->
|
||||||
case ets:info(emqx_modules) of
|
case ets:info(emqx_modules) of
|
||||||
undefined ->
|
undefined ->
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_rule_engine,
|
{application, emqx_rule_engine,
|
||||||
[{description, "EMQ X Rule Engine"},
|
[{description, "EMQ X Rule Engine"},
|
||||||
{vsn, "4.3.1"}, % strict semver, bump manually!
|
{vsn, "4.3.2"}, % strict semver, bump manually!
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, [emqx_rule_engine_sup, emqx_rule_registry]},
|
{registered, [emqx_rule_engine_sup, emqx_rule_registry]},
|
||||||
{applications, [kernel,stdlib,rulesql,getopt]},
|
{applications, [kernel,stdlib,rulesql,getopt]},
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
%% -*-: erlang -*-
|
%% -*-: erlang -*-
|
||||||
{"4.3.1",
|
{"4.3.2",
|
||||||
[ {"4.3.0",
|
[ {"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",
|
{"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, []}
|
||||||
]},
|
]},
|
||||||
{<<".*">>, []}
|
{<<".*">>, []}
|
||||||
]
|
]
|
||||||
|
|
|
@ -408,7 +408,7 @@ refresh_resource_status() ->
|
||||||
fun(#resource{id = ResId, type = ResType}) ->
|
fun(#resource{id = ResId, type = ResType}) ->
|
||||||
case emqx_rule_registry:find_resource_type(ResType) of
|
case emqx_rule_registry:find_resource_type(ResType) of
|
||||||
{ok, #resource_type{on_status = {Mod, OnStatus}}} ->
|
{ok, #resource_type{on_status = {Mod, OnStatus}}} ->
|
||||||
fetch_resource_status(Mod, OnStatus, ResId);
|
_ = fetch_resource_status(Mod, OnStatus, ResId);
|
||||||
_ -> ok
|
_ -> ok
|
||||||
end
|
end
|
||||||
end, emqx_rule_registry:get_resources()).
|
end, emqx_rule_registry:get_resources()).
|
||||||
|
@ -588,27 +588,26 @@ clear_action(Module, Destroy, ActionInstId) ->
|
||||||
fetch_resource_status(Module, OnStatus, ResId) ->
|
fetch_resource_status(Module, OnStatus, ResId) ->
|
||||||
case emqx_rule_registry:find_resource_params(ResId) of
|
case emqx_rule_registry:find_resource_params(ResId) of
|
||||||
{ok, ResParams = #resource_params{params = Params, status = #{is_alive := LastIsAlive}}} ->
|
{ok, ResParams = #resource_params{params = Params, status = #{is_alive := LastIsAlive}}} ->
|
||||||
try
|
NewStatus = try
|
||||||
NewStatus =
|
case Module:OnStatus(ResId, Params) of
|
||||||
case Module:OnStatus(ResId, Params) of
|
#{is_alive := LastIsAlive} = Status -> Status;
|
||||||
#{is_alive := LastIsAlive} = Status -> Status;
|
#{is_alive := true} = Status ->
|
||||||
#{is_alive := true} = Status ->
|
{ok, Type} = find_type(ResId),
|
||||||
{ok, Type} = find_type(ResId),
|
Name = alarm_name_of_resource_down(Type, ResId),
|
||||||
Name = alarm_name_of_resource_down(Type, ResId),
|
emqx_alarm:deactivate(Name),
|
||||||
emqx_alarm:deactivate(Name),
|
Status;
|
||||||
Status;
|
#{is_alive := false} = Status ->
|
||||||
#{is_alive := false} = Status ->
|
{ok, Type} = find_type(ResId),
|
||||||
{ok, Type} = find_type(ResId),
|
Name = alarm_name_of_resource_down(Type, ResId),
|
||||||
Name = alarm_name_of_resource_down(Type, ResId),
|
emqx_alarm:activate(Name, #{id => ResId, type => Type}),
|
||||||
emqx_alarm:activate(Name, #{id => ResId, type => Type}),
|
Status
|
||||||
Status
|
end
|
||||||
end,
|
|
||||||
emqx_rule_registry:add_resource_params(ResParams#resource_params{status = NewStatus}),
|
|
||||||
NewStatus
|
|
||||||
catch _Error:Reason:STrace ->
|
catch _Error:Reason:STrace ->
|
||||||
?LOG(error, "get resource status for ~p failed: ~0p", [ResId, {Reason, STrace}]),
|
?LOG(error, "get resource status for ~p failed: ~0p", [ResId, {Reason, STrace}]),
|
||||||
#{is_alive => false}
|
#{is_alive => false}
|
||||||
end;
|
end,
|
||||||
|
emqx_rule_registry:add_resource_params(ResParams#resource_params{status = NewStatus}),
|
||||||
|
NewStatus;
|
||||||
not_found ->
|
not_found ->
|
||||||
#{is_alive => false}
|
#{is_alive => false}
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in New Issue