mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-31 07:34:19 +00:00
add switch_sql_queue_manager_pause and switch_sql_queue_manager_resume
This commit is contained in:
1 parent
60bb1602d2
commit
efef505e26
2 files changed
+54
-20
No files matched your search
+51
-19
@@ -1266,6 +1266,7 @@ struct switch_sql_queue_manager {
|
||||
switch_memory_pool_t *pool;
|
||||
uint32_t max_trans;
|
||||
uint32_t confirm;
|
||||
uint8_t paused;
|
||||
};
|
||||
|
||||
static int qm_wake(switch_sql_queue_manager_t *qm)
|
||||
@@ -1400,6 +1401,52 @@ SWITCH_DECLARE(void) switch_sql_queue_manger_execute_sql_event_callback(switch_s
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void do_flush(switch_sql_queue_manager_t *qm, int i, switch_cache_db_handle_t *dbh)
|
||||
{
|
||||
void *pop = NULL;
|
||||
switch_queue_t *q = qm->sql_queue[i];
|
||||
|
||||
switch_mutex_lock(qm->mutex);
|
||||
while (switch_queue_trypop(q, &pop) == SWITCH_STATUS_SUCCESS) {
|
||||
if (pop) {
|
||||
if (dbh) {
|
||||
switch_cache_db_execute_sql(dbh, (char *) pop, NULL);
|
||||
}
|
||||
free(pop);
|
||||
}
|
||||
}
|
||||
switch_mutex_unlock(qm->mutex);
|
||||
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(void) switch_sql_queue_manager_resume(switch_sql_queue_manager_t *qm)
|
||||
{
|
||||
switch_mutex_lock(qm->mutex);
|
||||
qm->paused = 0;
|
||||
switch_mutex_unlock(qm->mutex);
|
||||
|
||||
qm_wake(qm);
|
||||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_sql_queue_manager_pause(switch_sql_queue_manager_t *qm, switch_bool_t flush)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
switch_mutex_lock(qm->mutex);
|
||||
qm->paused = 1;
|
||||
switch_mutex_unlock(qm->mutex);
|
||||
|
||||
if (flush) {
|
||||
for(i = 0; i < qm->numq; i++) {
|
||||
do_flush(qm, i, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_sql_queue_manager_size(switch_sql_queue_manager_t *qm, uint32_t index)
|
||||
{
|
||||
int size = 0;
|
||||
@@ -1462,25 +1509,6 @@ SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_start(switch_sql_queue_
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
static void do_flush(switch_sql_queue_manager_t *qm, int i, switch_cache_db_handle_t *dbh)
|
||||
{
|
||||
void *pop = NULL;
|
||||
switch_queue_t *q = qm->sql_queue[i];
|
||||
|
||||
switch_mutex_lock(qm->mutex);
|
||||
while (switch_queue_trypop(q, &pop) == SWITCH_STATUS_SUCCESS) {
|
||||
if (pop) {
|
||||
if (dbh) {
|
||||
switch_cache_db_execute_sql(dbh, (char *) pop, NULL);
|
||||
}
|
||||
free(pop);
|
||||
}
|
||||
}
|
||||
switch_mutex_unlock(qm->mutex);
|
||||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_destroy(switch_sql_queue_manager_t **qmp)
|
||||
{
|
||||
switch_sql_queue_manager_t *qm;
|
||||
@@ -1854,6 +1882,10 @@ static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread,
|
||||
uint32_t i, lc;
|
||||
uint32_t written = 0, iterations = 0;
|
||||
|
||||
if (qm->paused) {
|
||||
goto check;
|
||||
}
|
||||
|
||||
if (sql_manager.paused) {
|
||||
for (i = 0; i < qm->numq; i++) {
|
||||
do_flush(qm, i, NULL);
|
||||
|
||||
Reference in new issue
Block a user