fix: remove another redundant health check

Fixes https://emqx.atlassian.net/browse/EMQX-12521
This commit is contained in:
Thales Macedo Garitezi 2024-06-10 15:10:48 -03:00
parent 1a20a40218
commit 3c501e4f2a
2 changed files with 38 additions and 4 deletions

View File

@ -456,7 +456,7 @@ install_bridge_v2_helper(
ConnectorId = emqx_connector_resource:resource_id(
connector_type(BridgeV2Type), ConnectorName
),
emqx_resource_manager:add_channel(
_ = emqx_resource_manager:add_channel(
ConnectorId,
BridgeV2Id,
augment_channel_config(
@ -786,7 +786,11 @@ create_dry_run_helper(ConfRootKey, BridgeV2Type, ConnectorRawConf, BridgeV2RawCo
BridgeName,
BridgeV2Conf
),
case emqx_resource_manager:add_channel(ConnectorId, ChannelTestId, AugmentedConf) of
%% We'll perform it ourselves to get the resulting status afterwards.
Opts = #{perform_health_check => false},
case
emqx_resource_manager:add_channel(ConnectorId, ChannelTestId, AugmentedConf, Opts)
of
{error, Reason} ->
{error, Reason};
ok ->

View File

@ -14,6 +14,9 @@
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_resource_manager).
-feature(maybe_expr, enable).
-behaviour(gen_statem).
-include("emqx_resource.hrl").
@ -34,6 +37,7 @@
health_check/1,
channel_health_check/2,
add_channel/3,
add_channel/4,
remove_channel/2,
get_channels/1
]).
@ -133,6 +137,12 @@
ST =:= ?status_connecting; ST =:= ?status_connected; ST =:= ?status_disconnected
).
-type add_channel_opts() :: #{
%% Whether to immediately perform a health check after adding the channel.
%% Default: `true'
perform_health_check => boolean()
}.
%%------------------------------------------------------------------------------
%% API
%%------------------------------------------------------------------------------
@ -378,10 +388,30 @@ channel_health_check(ResId, ChannelId) ->
_ = health_check(ResId),
safe_call(ResId, {channel_health_check, ChannelId}, ?T_OPERATION).
-spec add_channel(
connector_resource_id(),
action_resource_id() | source_resource_id(),
_Config
) ->
ok | {error, term()}.
add_channel(ResId, ChannelId, Config) ->
add_channel(ResId, ChannelId, Config, _Opts = #{}).
-spec add_channel(
connector_resource_id(),
action_resource_id() | source_resource_id(),
_Config,
add_channel_opts()
) ->
ok | {error, term()}.
add_channel(ResId, ChannelId, Config, Opts) ->
Result = safe_call(ResId, {add_channel, ChannelId, Config}, ?T_OPERATION),
maybe
true ?= maps:get(perform_health_check, Opts, true),
%% Wait for health_check to finish
_ = channel_health_check(ResId, ChannelId),
ok
end,
Result.
remove_channel(ResId, ChannelId) ->