switch_size_t newlen;
int lc = 0, wrote = 0, do_sleep = 1;
uint32_t sanity = 120;
-
+ int too_long = SWITCH_SQL_QUEUE_LEN / 2;
+ int auto_pause = 0;
+
switch_assert(sqlbuf);
while (!sql_manager.event_db) {
lc = switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]);
+
+ if (lc > too_long) {
+ if (!auto_pause) {
+ auto_pause = 1;
+ switch_core_session_ctl(SCSC_PAUSE_INBOUND, &auto_pause);
+ auto_pause = 1;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL Queue overflowing [%d], Pausing calls.\n", lc);
+ }
+ } else {
+ if (auto_pause && lc < 1000) {
+ auto_pause = 0;
+ switch_core_session_ctl(SCSC_PAUSE_INBOUND, &auto_pause);
+ auto_pause = 0;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL Queue back to normal size, resuming..\n");
+ }
+ }
+
skip:
wrote = 0;
if (!lc) {
switch_thread_cond_wait(sql_manager.cond, sql_manager.cond_mutex);
} else if (wrote) {
- if (lc > 200) {
+ if (lc > 2000) {
do_sleep = 0;
} else {
do_sleep = 1;