refactor(rule_engine): use more helper functions
Follow up to https://github.com/emqx/emqx/pull/10251#discussion_r1150710899 and https://github.com/emqx/emqx/pull/10251#discussion_r1150720420
This commit is contained in:
parent
1824e7efcc
commit
d126c7dc62
|
@ -1,7 +1,7 @@
|
||||||
%% -*- mode: erlang -*-
|
%% -*- mode: erlang -*-
|
||||||
{application, emqx_bridge, [
|
{application, emqx_bridge, [
|
||||||
{description, "EMQX bridges"},
|
{description, "EMQX bridges"},
|
||||||
{vsn, "0.1.13"},
|
{vsn, "0.1.14"},
|
||||||
{registered, [emqx_bridge_sup]},
|
{registered, [emqx_bridge_sup]},
|
||||||
{mod, {emqx_bridge_app, []}},
|
{mod, {emqx_bridge_app, []}},
|
||||||
{applications, [
|
{applications, [
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{application, emqx_rule_engine, [
|
{application, emqx_rule_engine, [
|
||||||
{description, "EMQX Rule Engine"},
|
{description, "EMQX Rule Engine"},
|
||||||
% strict semver, bump manually!
|
% strict semver, bump manually!
|
||||||
{vsn, "5.0.11"},
|
{vsn, "5.0.12"},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, [emqx_rule_engine_sup, emqx_rule_engine]},
|
{registered, [emqx_rule_engine_sup, emqx_rule_engine]},
|
||||||
{applications, [kernel, stdlib, rulesql, getopt, emqx_ctl]},
|
{applications, [kernel, stdlib, rulesql, getopt, emqx_ctl]},
|
||||||
|
|
|
@ -319,14 +319,8 @@ get_basic_usage_info() ->
|
||||||
ReferencedBridges =
|
ReferencedBridges =
|
||||||
lists:foldl(
|
lists:foldl(
|
||||||
fun(#{actions := Actions, from := Froms}, Acc) ->
|
fun(#{actions := Actions, from := Froms}, Acc) ->
|
||||||
BridgeIDs0 =
|
BridgeIDs0 = get_referenced_hookpoints(Froms),
|
||||||
[
|
BridgeIDs1 = get_egress_bridges(Actions),
|
||||||
BridgeID
|
|
||||||
|| From <- Froms,
|
|
||||||
{ok, BridgeID} <-
|
|
||||||
[emqx_bridge_resource:bridge_hookpoint_to_bridge_id(From)]
|
|
||||||
],
|
|
||||||
BridgeIDs1 = lists:filter(fun is_binary/1, Actions),
|
|
||||||
tally_referenced_bridges(BridgeIDs0 ++ BridgeIDs1, Acc)
|
tally_referenced_bridges(BridgeIDs0 ++ BridgeIDs1, Acc)
|
||||||
end,
|
end,
|
||||||
#{},
|
#{},
|
||||||
|
@ -490,10 +484,8 @@ forwards_to_bridge(Actions, BridgeId) ->
|
||||||
lists:any(fun(A) -> A =:= BridgeId end, Actions).
|
lists:any(fun(A) -> A =:= BridgeId end, Actions).
|
||||||
|
|
||||||
references_ingress_bridge(Froms, BridgeId) ->
|
references_ingress_bridge(Froms, BridgeId) ->
|
||||||
lists:any(
|
lists:member(
|
||||||
fun(ReferenceBridgeId) ->
|
BridgeId,
|
||||||
BridgeId =:= ReferenceBridgeId
|
|
||||||
end,
|
|
||||||
[
|
[
|
||||||
RefBridgeId
|
RefBridgeId
|
||||||
|| From <- Froms,
|
|| From <- Froms,
|
||||||
|
@ -501,3 +493,14 @@ references_ingress_bridge(Froms, BridgeId) ->
|
||||||
[emqx_bridge_resource:bridge_hookpoint_to_bridge_id(From)]
|
[emqx_bridge_resource:bridge_hookpoint_to_bridge_id(From)]
|
||||||
]
|
]
|
||||||
).
|
).
|
||||||
|
|
||||||
|
get_referenced_hookpoints(Froms) ->
|
||||||
|
[
|
||||||
|
BridgeID
|
||||||
|
|| From <- Froms,
|
||||||
|
{ok, BridgeID} <-
|
||||||
|
[emqx_bridge_resource:bridge_hookpoint_to_bridge_id(From)]
|
||||||
|
].
|
||||||
|
|
||||||
|
get_egress_bridges(Actions) ->
|
||||||
|
lists:filter(fun is_binary/1, Actions).
|
||||||
|
|
Loading…
Reference in New Issue