Mercurial > prosody-modules
changeset 1207:c6b8ae5a8369
mod_mam_sql: Reconnect if the connection should be dropped
author | Rob Hoelz <rob@hoelz.ro> |
---|---|
date | Mon, 02 Sep 2013 20:10:10 +0200 (2013-09-02) |
parents | 04bf76c3e4c6 |
children | defa479a7d53 |
files | mod_mam_sql/mod_mam_sql.lua |
diffstat | 1 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_mam_sql/mod_mam_sql.lua Mon Sep 02 19:55:51 2013 +0200 +++ b/mod_mam_sql/mod_mam_sql.lua Mon Sep 02 20:10:10 2013 +0200 @@ -49,17 +49,20 @@ }; end +local connect + local function test_connection() if not connection then return nil; end if connection:ping() then return true; else module:log("debug", "Database connection closed"); + module:log("debug", "Attempting to reconnect"); connection = nil; - connections[dburi] = nil; + return connect(); end end -local function connect() +function connect() if not test_connection() then prosody.unlock_globals(); local dbh, err = DBI.Connect( @@ -117,6 +120,9 @@ if not connection then return nil, 'connection failed'; end + if not test_connection() then + return nil, 'connection failed'; + end -- do prepared statement stuff local stmt, err = connection:prepare(sql); if not stmt and not test_connection() then