fix: for connection used ecpool, let worker do health check fun

let it be same with ecpool:pick_and_do/3 for checkfun use format as {M,F,A}
This commit is contained in:
JimMoen 2023-03-23 16:23:56 +08:00
parent 2803aff798
commit 65f468f706
No known key found for this signature in database
GPG Key ID: 87A520B4F76BA86D
1 changed files with 3 additions and 2 deletions

View File

@ -67,13 +67,14 @@ stop_pool(Name) ->
health_check_ecpool_workers(PoolName, CheckFunc) ->
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)],
DoPerWorker =
fun(Worker) ->
case ecpool_worker:client(Worker) of
{ok, Conn} ->
erlang:is_process_alive(Conn) andalso CheckFunc(Conn);
erlang:is_process_alive(Conn) andalso
ecpool_worker:exec(Worker, CheckFunc, Timeout);
_ ->
false
end