diff options
author | seanbright <seanbright@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-08-14 15:03:03 +0000 |
---|---|---|
committer | seanbright <seanbright@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-08-14 15:03:03 +0000 |
commit | 1a0b3cb4c4d0185789ed54ca2bc6e200c113e75a (patch) | |
tree | e9acc75dc0f6b40de94c4282fd04099888447054 /cdr | |
parent | b3618774c050a1650b3511263e18f2d89fdd2934 (diff) |
If we detect that we are no longer connected, try to reconnect a few times
before giving up. This relies on the timeout settings in the freetds.conf
file and, unfortunately, on a recent version of FreeTDS (0.82 or newer).
I either need to change the current execs to be non-blocking (which I do
not want to do) or we have to force people to run with the latest and
greatest of FreeTDS. I'm on the fence...
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@137780 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr')
-rw-r--r-- | cdr/cdr_tds.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/cdr/cdr_tds.c b/cdr/cdr_tds.c index cf1780508..fd3f32864 100644 --- a/cdr/cdr_tds.c +++ b/cdr/cdr_tds.c @@ -114,6 +114,7 @@ static int tds_log(struct ast_cdr *cdr) char *accountcode, *src, *dst, *dcontext, *clid, *channel, *dstchannel, *lastapp, *lastdata, *uniqueid, *userfield = NULL; RETCODE erc; int res = -1; + int attempt = 1; accountcode = anti_injection(cdr->accountcode, 20); src = anti_injection(cdr->src, 80); @@ -136,10 +137,15 @@ static int tds_log(struct ast_cdr *cdr) userfield = anti_injection(cdr->userfield, AST_MAX_USER_FIELD); } +retry: /* Ensure that we are connected */ if (!settings->connected) { + ast_log(LOG_NOTICE, "Attempting to reconnect to %s (Attempt %d)\n", settings->hostname, attempt); if (mssql_connect()) { /* Connect failed */ + if (attempt++ < 3) { + goto retry; + } goto done; } } @@ -186,13 +192,25 @@ static int tds_log(struct ast_cdr *cdr) } if (erc == FAIL) { - ast_log(LOG_ERROR, "Failed to build INSERT statement, no CDR was logged.\n"); - goto done; + if (attempt++ < 3) { + ast_log(LOG_NOTICE, "Failed to build INSERT statement, retrying...\n"); + mssql_disconnect(); + goto retry; + } else { + ast_log(LOG_ERROR, "Failed to build INSERT statement, no CDR was logged.\n"); + goto done; + } } if (dbsqlexec(settings->dbproc) == FAIL) { - ast_log(LOG_ERROR, "Failed to execute INSERT statement, no CDR was logged.\n"); - goto done; + if (attempt++ < 3) { + ast_log(LOG_NOTICE, "Failed to execute INSERT statement, retrying...\n"); + mssql_disconnect(); + goto retry; + } else { + ast_log(LOG_ERROR, "Failed to execute INSERT statement, no CDR was logged.\n"); + goto done; + } } /* Consume any results we might get back (this is more of a sanity check than |