25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-24 17:29:28 +01:00
xmpp.chapril.org-ejabberd/src/odbc/ejabberd_odbc_sup.erl
Mickaël Rémond c7bafe0056 * src/odbc/ejabberd_odbc.erl: Added a way to retry database
connection connect for 5 minutes when the connection is lost. No further
connection is retry after 5 minutes (EJAB-22 & EJAB-25)
* src/odbc/ejabberd_odbc_sup.erl: likewise

SVN Revision: 485
2006-01-13 18:05:10 +00:00

49 lines
1.2 KiB
Erlang

%%%----------------------------------------------------------------------
%%% File : ejabberd_odbc_sup.erl
%%% Author : Alexey Shchepin <alexey@sevcom.net>
%%% Purpose : ODBC connections supervisor
%%% Created : 22 Dec 2004 by Alexey Shchepin <alexey@sevcom.net>
%%% Id : $Id$
%%%----------------------------------------------------------------------
-module(ejabberd_odbc_sup).
-author('alexey@sevcom.net').
-vsn('$Revision$ ').
-export([start_link/1,
init/1,
get_pids/1,
get_random_pid/1
]).
-include("ejabberd.hrl").
start_link(Host) ->
supervisor:start_link({local, gen_mod:get_module_proc(Host, ?MODULE)},
?MODULE, [Host]).
init([Host]) ->
% TODO
N = 10,
{ok, {{one_for_one, 10, 6},
lists:map(
fun(I) ->
{I,
{ejabberd_odbc, start_link, [Host]},
transient,
brutal_kill,
worker,
[?MODULE]}
end, lists:seq(1, N))}}.
get_pids(Host) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
[Child ||
{_Id, Child, _Type, _Modules} <- supervisor:which_children(Proc),
Child /= undefined].
get_random_pid(Host) ->
Pids = get_pids(Host),
lists:nth(erlang:phash(now(), length(Pids)), Pids).