fix(mongo): update the health check method
This commit is contained in:
parent
cb317b3d7a
commit
d1b3377c52
|
@ -8,7 +8,7 @@
|
||||||
{mysql, {git, "https://github.com/emqx/mysql-otp", {tag, "1.7.1"}}},
|
{mysql, {git, "https://github.com/emqx/mysql-otp", {tag, "1.7.1"}}},
|
||||||
{epgsql, {git, "https://github.com/epgsql/epgsql", {tag, "4.4.0"}}},
|
{epgsql, {git, "https://github.com/epgsql/epgsql", {tag, "4.4.0"}}},
|
||||||
%% NOTE: mind poolboy version when updating mongodb-erlang version
|
%% NOTE: mind poolboy version when updating mongodb-erlang version
|
||||||
{mongodb, {git,"https://github.com/emqx/mongodb-erlang", {tag, "v3.0.8"}}},
|
{mongodb, {git,"https://github.com/emqx/mongodb-erlang", {tag, "v3.0.9"}}},
|
||||||
%% NOTE: mind poolboy version when updating eredis_cluster version
|
%% NOTE: mind poolboy version when updating eredis_cluster version
|
||||||
{eredis_cluster, {git, "https://github.com/emqx/eredis_cluster", {tag, "0.6.7"}}},
|
{eredis_cluster, {git, "https://github.com/emqx/eredis_cluster", {tag, "0.6.7"}}},
|
||||||
%% mongodb-erlang uses a special fork https://github.com/comtihon/poolboy.git
|
%% mongodb-erlang uses a special fork https://github.com/comtihon/poolboy.git
|
||||||
|
|
|
@ -148,15 +148,24 @@ on_query(InstId, {Action, Collection, Selector, Docs}, AfterQuery, #{poolname :=
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-dialyzer({nowarn_function, [on_health_check/2]}).
|
-dialyzer({nowarn_function, [on_health_check/2]}).
|
||||||
on_health_check(_InstId, #{test_opts := TestOpts} = State) ->
|
on_health_check(_InstId, #{poolname := PoolName} = State) ->
|
||||||
case mc_worker_api:connect(TestOpts) of
|
case health_check(PoolName) of
|
||||||
{ok, TestConn} ->
|
true -> {ok, State};
|
||||||
mc_worker_api:disconnect(TestConn),
|
false -> {error, health_check_failed, State}
|
||||||
{ok, State};
|
|
||||||
{error, _} ->
|
|
||||||
{error, health_check_failed, State}
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
health_check(PoolName) ->
|
||||||
|
Status = [begin
|
||||||
|
case ecpool_worker:client(Worker) of
|
||||||
|
{ok, Conn} ->
|
||||||
|
%% we don't care if this returns something or not, we just to test the connection
|
||||||
|
Res = mongo_api:find_one(Conn, <<"foo">>, {}, #{}),
|
||||||
|
Res == undefined orelse is_map(Res);
|
||||||
|
_ -> false
|
||||||
|
end
|
||||||
|
end || {_WorkerName, Worker} <- ecpool:workers(PoolName)],
|
||||||
|
length(Status) > 0 andalso lists:all(fun(St) -> St =:= true end, Status).
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
connect(Opts) ->
|
connect(Opts) ->
|
||||||
Type = proplists:get_value(mongo_type, Opts, single),
|
Type = proplists:get_value(mongo_type, Opts, single),
|
||||||
|
|
Loading…
Reference in New Issue