From 8976e25b7a70fda74f6fcf791dde50e74cc4fa99 Mon Sep 17 00:00:00 2001 From: EMQ-YangM Date: Wed, 26 Jan 2022 11:20:09 +0800 Subject: [PATCH 1/2] fix(emqx_resource_instance): create health_check process when create resources synchronously --- apps/emqx_resource/src/emqx_resource_instance.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/emqx_resource/src/emqx_resource_instance.erl b/apps/emqx_resource/src/emqx_resource_instance.erl index 0cdeeae50..42819abd2 100644 --- a/apps/emqx_resource/src/emqx_resource_instance.erl +++ b/apps/emqx_resource/src/emqx_resource_instance.erl @@ -247,7 +247,12 @@ start_and_check(InstId, ResourceType, Config, Opts, Data) -> Data2 = Data#{state => ResourceState}, ets:insert(emqx_resource_instance, {InstId, Data2}), case maps:get(async_create, Opts, false) of - false -> do_health_check(Data2); + false -> case do_health_check(Data2) of + ok -> emqx_resource_health_check:create_checker(InstId, + maps:get(health_check_interval, Opts, 15000), + maps:get(health_check_timeout, Opts, 10000)); + {error, Reason} -> {error, Reason} + end; true -> emqx_resource_health_check:create_checker(InstId, maps:get(health_check_interval, Opts, 15000), maps:get(health_check_timeout, Opts, 10000)) From 3b3f3fed76c1aa2daddf5b38d2c4b06501c7b02f Mon Sep 17 00:00:00 2001 From: EMQ-YangM Date: Mon, 7 Feb 2022 17:48:26 +0800 Subject: [PATCH 2/2] refactor(emqx_resource_instance): add function create_default_checker --- apps/emqx_resource/src/emqx_resource_instance.erl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/emqx_resource/src/emqx_resource_instance.erl b/apps/emqx_resource/src/emqx_resource_instance.erl index 42819abd2..a07f3e78c 100644 --- a/apps/emqx_resource/src/emqx_resource_instance.erl +++ b/apps/emqx_resource/src/emqx_resource_instance.erl @@ -248,20 +248,21 @@ start_and_check(InstId, ResourceType, Config, Opts, Data) -> ets:insert(emqx_resource_instance, {InstId, Data2}), case maps:get(async_create, Opts, false) of false -> case do_health_check(Data2) of - ok -> emqx_resource_health_check:create_checker(InstId, - maps:get(health_check_interval, Opts, 15000), - maps:get(health_check_timeout, Opts, 10000)); + ok -> create_default_checker(InstId, Opts); {error, Reason} -> {error, Reason} end; - true -> emqx_resource_health_check:create_checker(InstId, - maps:get(health_check_interval, Opts, 15000), - maps:get(health_check_timeout, Opts, 10000)) + true -> create_default_checker(InstId, Opts) end; {error, Reason} -> ets:insert(emqx_resource_instance, {InstId, Data#{status => stopped}}), {error, Reason} end. +create_default_checker(InstId, Opts) -> + emqx_resource_health_check:create_checker(InstId, + maps:get(health_check_interval, Opts, 15000), + maps:get(health_check_timeout, Opts, 10000)). + do_stop(InstId) when is_binary(InstId) -> do_with_instance_data(InstId, fun do_stop/1, []); do_stop(#{state := undefined}) ->