* src/mod_vcard_odbc.erl: likewise.
* src/odbc/mysql.sql: Fixed MySQL database creation script: Was
not properly working with all MySQL version.
+ * 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.
+ * src/odbc/ejabberd_odbc_sup.erl: likewise.
2006-01-13 Alexey Shchepin <alexey@sevcom.net>
%% {noreply, State, Timeout} |
%% {stop, Reason, State} (terminate/2 is called)
%%----------------------------------------------------------------------
+%% We receive the down signal when we loose the MySQL connection (we are
+%% monitoring the connection)
+%% => We exit and let the supervisor restart the connection.
+handle_info({'DOWN', _MonitorRef, process, _Pid, _Info}, State) ->
+ {stop, connection_dropped, State};
handle_info(_Info, State) ->
{noreply, State}.
%%%----------------------------------------------------------------------
%%% Internal functions
%%%----------------------------------------------------------------------
-
sql_query_internal(State, Query) ->
case State#state.db_type of
odbc ->
{error, Reason} ->
?ERROR_MSG("ODBC connection (~s) failed: ~p~n",
[SQLServer, Reason]),
+ %% If we can't connect we wait for 30 seconds before retrying
+ timer:sleep(30000),
{stop, odbc_connection_failed}
end.
{ok, #state{db_ref = Ref, db_type = pgsql}};
{error, Reason} ->
?ERROR_MSG("PostgreSQL connection failed: ~p~n", [Reason]),
+ %% If we can't connect we wait for 30 seconds before retrying
+ timer:sleep(30000),
{stop, pgsql_connection_failed}
end.
NoLogFun = fun(_Level,_Format,_Argument) -> ok end,
case mysql_conn:start(Server, ?MYSQL_PORT, Username, Password, DB, NoLogFun) of
{ok, Ref} ->
+ erlang:monitor(process, Ref),
{ok, #state{db_ref = Ref, db_type = mysql}};
{error, Reason} ->
?ERROR_MSG("MySQL connection failed: ~p~n", [Reason]),
+ %% If we can't connect we wait for 30 seconds before retrying
+ timer:sleep(30000),
{stop, mysql_connection_failed}
end.