Merge pull request #6863 from EMQ-YangM/fix_hc

fix(emqx_resource_instance): create health_check process when create …
This commit is contained in:
Yang Miao 2022-02-09 13:36:34 +08:00 committed by GitHub
commit e9c65447c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -247,16 +247,22 @@ 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);
true -> emqx_resource_health_check:create_checker(InstId,
maps:get(health_check_interval, Opts, 15000),
maps:get(health_check_timeout, Opts, 10000))
false -> case do_health_check(Data2) of
ok -> create_default_checker(InstId, Opts);
{error, Reason} -> {error, Reason}
end;
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}) ->