[asterisk-commits] file: branch file/cdrbatchretry r38365 - in /team/file/cdrbatchretry: ./ conf...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Jul 27 11:34:26 MST 2006


Author: file
Date: Thu Jul 27 13:34:26 2006
New Revision: 38365

URL: http://svn.digium.com/view/asterisk?rev=38365&view=rev
Log:
Add option to limit how many deferrals can occur. If you ever get up to 10 deferrals and the engine still can't post your CDR, something is wrong.

Modified:
    team/file/cdrbatchretry/cdr.c
    team/file/cdrbatchretry/configs/cdr.conf.sample

Modified: team/file/cdrbatchretry/cdr.c
URL: http://svn.digium.com/view/asterisk/team/file/cdrbatchretry/cdr.c?rev=38365&r1=38364&r2=38365&view=diff
==============================================================================
--- team/file/cdrbatchretry/cdr.c (original)
+++ team/file/cdrbatchretry/cdr.c Thu Jul 27 13:34:26 2006
@@ -75,6 +75,7 @@
 struct ast_cdr_batch_item {
 	struct ast_cdr *cdr;
 	int engine[MAX_ENGINES];
+	int deferrals;
 	AST_LIST_ENTRY(ast_cdr_batch_item) list;
 };
 
@@ -89,6 +90,7 @@
 #define BATCH_TIME_DEFAULT 300
 #define BATCH_SCHEDULER_ONLY_DEFAULT 0
 #define BATCH_SAFE_SHUTDOWN_DEFAULT 1
+#define BATCH_MAX_DEFERRALS 10
 
 static int enabled;
 static int batchmode;
@@ -96,6 +98,7 @@
 static int batchtime;
 static int batchscheduleronly;
 static int batchsafeshutdown;
+static int batchmaxdeferrals;
 
 /* these are used to wake up the CDR thread when there's work to do */
 AST_MUTEX_DEFINE_STATIC(cdr_pending_lock);
@@ -810,6 +813,8 @@
 
 	/* Thankfully we don't need to hold the lock on the above since it only exists to us */
 	while ((batch_item = AST_LIST_REMOVE_HEAD(&local_batch_list, list))) {
+		/* Increment deferral count */
+		batch_item->deferrals++;
 		/* Reset defer state to 0 */
 		defer = 0;
 		/* Now we have to process this batched item */
@@ -838,7 +843,11 @@
 			}
 		}
 		AST_LIST_UNLOCK(&be_list);
-		/* Okay... if we need to defer this entry for another attempt, do so... otherwise drop it */
+		/* If this has reached the maximum number of deferrals... don't defer it any longer */
+		if (batchmaxdeferrals > 0 && batch_item->deferrals == batchmaxdeferrals) {
+			defer = 0;
+		}
+		/* Okay... if we need to defer this entry for another attempt and we have not reached the max, do so... otherwise drop it */
 		if (defer) {
 			/* Insert it into the regular batch list */
 			AST_LIST_LOCK(&batch_list);
@@ -1015,6 +1024,7 @@
 			ast_cli(fd, "CDR current batch size: %d record%s\n", cnt, (cnt != 1) ? "s" : "");
 			ast_cli(fd, "CDR maximum batch size: %d record%s\n", batchsize, (batchsize != 1) ? "s" : "");
 			ast_cli(fd, "CDR maximum batch time: %d second%s\n", batchtime, (batchtime != 1) ? "s" : "");
+			ast_cli(fd, "CDR maximum batch deferrals: %d\n", batchmaxdeferrals);
 			ast_cli(fd, "CDR next scheduled batch processing time: %ld second%s\n", nextbatchtime, (nextbatchtime != 1) ? "s" : "");
 		}
 		AST_LIST_LOCK(&be_list);
@@ -1066,11 +1076,13 @@
 	const char *size_value;
 	const char *time_value;
 	const char *end_before_h_value;
+	const char *batchmaxdeferrals_value;
 	int cfg_size;
 	int cfg_time;
 	int was_enabled;
 	int was_batchmode;
 	int res=0;
+	int batchmaxdeferrals_val;
 
 	AST_LIST_LOCK(&batch_list);
 
@@ -1078,6 +1090,7 @@
 	batchtime = BATCH_TIME_DEFAULT;
 	batchscheduleronly = BATCH_SCHEDULER_ONLY_DEFAULT;
 	batchsafeshutdown = BATCH_SAFE_SHUTDOWN_DEFAULT;
+	batchmaxdeferrals = BATCH_MAX_DEFERRALS;
 	was_enabled = enabled;
 	was_batchmode = batchmode;
 	enabled = 1;
@@ -1115,6 +1128,14 @@
 				ast_log(LOG_WARNING, "Invalid maximum batch time '%d' specified, using default\n", cfg_time);
 			else
 				batchtime = cfg_time;
+		}
+		if ((batchmaxdeferrals_value = ast_variable_retrieve(config, "general", "maxdeferrals"))) {
+			if (sscanf(batchmaxdeferrals_value, "%d", &batchmaxdeferrals_val) < 1)
+				ast_log(LOG_WARNING, "Unable to convert '%s' to a numeric value.\n", batchmaxdeferrals_value);
+			else if (batchmaxdeferrals_val < 0)
+				ast_log(LOG_WARNING, "Invalid maximum batch deferrals '%d' specified, using default\n", batchmaxdeferrals_val);
+			else
+				batchmaxdeferrals = batchmaxdeferrals_val;
 		}
 		if ((end_before_h_value = ast_variable_retrieve(config, "general", "endbeforehexten")))
 			ast_set2_flag(&ast_options, ast_true(end_before_h_value), AST_OPT_FLAG_END_CDR_BEFORE_H_EXTEN);

Modified: team/file/cdrbatchretry/configs/cdr.conf.sample
URL: http://svn.digium.com/view/asterisk/team/file/cdrbatchretry/configs/cdr.conf.sample?rev=38365&r1=38364&r2=38365&view=diff
==============================================================================
--- team/file/cdrbatchretry/configs/cdr.conf.sample (original)
+++ team/file/cdrbatchretry/configs/cdr.conf.sample Thu Jul 27 13:34:26 2006
@@ -42,6 +42,11 @@
 ; set this to "no".  Default is "no".
 ;scheduleronly=no
 
+; Define the maximum number of times a CDR record can be deferred to be posted again
+; to all engines that failed to post it, or that deferred it.
+; Default is 10. For no limit set this to 0.
+;maxdeferrals=10
+
 ; When shutting down asterisk, you can block until the CDRs are submitted.  If
 ; you don't, then data will likely be lost.  You can always check the size of
 ; the CDR batch buffer with the CLI "cdr status" command.  To enable blocking on



More information about the asterisk-commits mailing list