Merge pull request #10217 from JimMoen/conn-health-check-with-worker
fix: for connection used ecpool, let worker do health check fun
This commit is contained in:
commit
798597c834
|
@ -67,13 +67,14 @@ stop_pool(Name) ->
|
||||||
health_check_ecpool_workers(PoolName, CheckFunc) ->
|
health_check_ecpool_workers(PoolName, CheckFunc) ->
|
||||||
health_check_ecpool_workers(PoolName, CheckFunc, ?HEALTH_CHECK_TIMEOUT).
|
health_check_ecpool_workers(PoolName, CheckFunc, ?HEALTH_CHECK_TIMEOUT).
|
||||||
|
|
||||||
health_check_ecpool_workers(PoolName, CheckFunc, Timeout) when is_function(CheckFunc) ->
|
health_check_ecpool_workers(PoolName, CheckFunc, Timeout) ->
|
||||||
Workers = [Worker || {_WorkerName, Worker} <- ecpool:workers(PoolName)],
|
Workers = [Worker || {_WorkerName, Worker} <- ecpool:workers(PoolName)],
|
||||||
DoPerWorker =
|
DoPerWorker =
|
||||||
fun(Worker) ->
|
fun(Worker) ->
|
||||||
case ecpool_worker:client(Worker) of
|
case ecpool_worker:client(Worker) of
|
||||||
{ok, Conn} ->
|
{ok, Conn} ->
|
||||||
erlang:is_process_alive(Conn) andalso CheckFunc(Conn);
|
erlang:is_process_alive(Conn) andalso
|
||||||
|
ecpool_worker:exec(Worker, CheckFunc, Timeout);
|
||||||
_ ->
|
_ ->
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,8 +31,7 @@
|
||||||
connect/1,
|
connect/1,
|
||||||
do_get_status/1,
|
do_get_status/1,
|
||||||
do_async_reply/2,
|
do_async_reply/2,
|
||||||
worker_do_query/4,
|
worker_do_query/4
|
||||||
worker_do_get_status/1
|
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-import(hoconsc, [mk/2, enum/1, ref/2]).
|
-import(hoconsc, [mk/2, enum/1, ref/2]).
|
||||||
|
@ -165,18 +164,14 @@ on_get_status(_InstanceId, #{poolname := Pool}) ->
|
||||||
Health = emqx_plugin_libs_pool:health_check_ecpool_workers(Pool, fun ?MODULE:do_get_status/1),
|
Health = emqx_plugin_libs_pool:health_check_ecpool_workers(Pool, fun ?MODULE:do_get_status/1),
|
||||||
status_result(Health).
|
status_result(Health).
|
||||||
|
|
||||||
do_get_status(Conn) ->
|
do_get_status(_Conn) ->
|
||||||
%% because the dynamodb driver connection process is the ecpool worker self
|
%% because the dynamodb driver connection process is the ecpool worker self
|
||||||
%% so we must call the checker function inside the worker
|
%% so we must call the checker function inside the worker
|
||||||
ListTables = ecpool_worker:exec(Conn, {?MODULE, worker_do_get_status, []}, infinity),
|
case erlcloud_ddb2:list_tables() of
|
||||||
case ListTables of
|
|
||||||
{ok, _} -> true;
|
{ok, _} -> true;
|
||||||
_ -> false
|
_ -> false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
worker_do_get_status(_) ->
|
|
||||||
erlcloud_ddb2:list_tables().
|
|
||||||
|
|
||||||
status_result(_Status = true) -> connected;
|
status_result(_Status = true) -> connected;
|
||||||
status_result(_Status = false) -> connecting.
|
status_result(_Status = false) -> connecting.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue