[Asterisk-code-review] app_queue: load queues and members from Realtime when needed (asterisk[master])

Friendly Automation asteriskteam at digium.com
Fri Feb 11 12:43:19 CST 2022


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/17987 )

Change subject: app_queue: load queues and members from Realtime when needed
......................................................................

app_queue: load queues and members from Realtime when needed

There are a lot of Queue AMI actions and Queue applications
which do not load queue and queue members from Realtime.

AMI actions
QueuePause - if queue not in memory - response "Interface not found".
QueueStatus/QueueSummary - if queue not in memory - empty response.

Applications:
PauseQueueMember - if queue not in memory
	Attempt to pause interface %s, not found
UnpauseQueueMember - if queue not in memory
	Attempt to unpause interface xxxxx, not found

This patch adds a new function load_realtime_queues
which loads queue and queue members for desired queue
or all queues and all members if param 'queuename' is NULL or empty.
Calls the function load_realtime_queues when needed.

Also this patch fixes leak of ast_config in function set_member_value.

Also this patch fixes incorrect LOG_WARNING when pausing/unpausing
already paused/unpaused member.
The function ast_update_realtime returns 0 when no record modified.
So 0 is not an error to warn about.

ASTERISK-29873 #close
ASTERISK-18416 #close
ASTERISK-27597 #close

Change-Id: I554ee0eebde93bd8f49df7f84b74acb21edcb99c
---
M apps/app_queue.c
A doc/CHANGES-staging/load_realtime_queues.txt
2 files changed, 54 insertions(+), 1 deletion(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/apps/app_queue.c b/apps/app_queue.c
index 9bd0537..8ec98e2 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -3899,6 +3899,40 @@
 	return q;
 }
 
+/*!
+ * \internal
+ * \brief Load queues and members from realtime.
+ *
+ * \param queuename - name of the desired queue to load or empty if need to load all queues
+*/
+static void load_realtime_queues(const char *queuename)
+{
+	struct ast_config *cfg = NULL;
+	char *category = NULL;
+	const char *name = NULL;
+	struct call_queue *q = NULL;
+
+	if (!ast_check_realtime("queues")) {
+		return;
+	}
+
+	if (ast_strlen_zero(queuename)) {
+		if ((cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL))) {
+			while ((category = ast_category_browse(cfg, category))) {
+				name = ast_variable_retrieve(cfg, category, "name");
+				if (!ast_strlen_zero(name) && (q = find_load_queue_rt_friendly(name))) {
+					queue_unref(q);
+				}
+			}
+			ast_config_destroy(cfg);
+		}
+	} else {
+		if ((q = find_load_queue_rt_friendly(queuename))) {
+			queue_unref(q);
+		}
+	}
+}
+
 static int update_realtime_member_field(struct member *mem, const char *queue_name, const char *field, const char *value)
 {
 	int ret = -1;
@@ -3907,7 +3941,7 @@
  		return ret;
 	}
 
-	if ((ast_update_realtime("queue_members", "uniqueid", mem->rt_uniqueid, field, value, SENTINEL)) > 0) {
+	if ((ast_update_realtime("queue_members", "uniqueid", mem->rt_uniqueid, field, value, SENTINEL)) >= 0) {
 		ret = 0;
 	}
 
@@ -7663,6 +7697,10 @@
 	struct call_queue *q;
 	struct ao2_iterator queue_iter;
 
+	if (ast_check_realtime("queues")) {
+		load_realtime_queues(queuename);
+	}
+
 	queue_iter = ao2_iterator_init(queues, 0);
 	while ((q = ao2_t_iterator_next(&queue_iter, "Iterate over queues"))) {
 		ao2_lock(q);
@@ -7834,6 +7872,8 @@
 						queue_unref(q);
 					}
 				}
+
+				ast_config_destroy(queue_config);
 			}
 		}
 
@@ -10178,6 +10218,10 @@
 	struct ao2_iterator queue_iter;
 	struct ao2_iterator mem_iter;
 
+	if (ast_check_realtime("queues")) {
+		load_realtime_queues(queuefilter);
+	}
+
 	astman_send_listack(s, m, "Queue summary will follow", "start");
 	time(&now);
 	idText[0] = '\0';
@@ -10256,6 +10300,10 @@
 	struct ao2_iterator queue_iter;
 	struct ao2_iterator mem_iter;
 
+	if (ast_check_realtime("queues")) {
+		load_realtime_queues(queuefilter);
+	}
+
 	astman_send_listack(s, m, "Queue status will follow", "start");
 	time(&now);
 	idText[0] = '\0';
diff --git a/doc/CHANGES-staging/load_realtime_queues.txt b/doc/CHANGES-staging/load_realtime_queues.txt
new file mode 100644
index 0000000..68a4a8b
--- /dev/null
+++ b/doc/CHANGES-staging/load_realtime_queues.txt
@@ -0,0 +1,5 @@
+Subject: app_queue
+
+Load queues and members from Realtime for
+AMI actions: QueuePause, QueueStatus and QueueSummary,
+Applications: PauseQueueMember and UnpauseQueueMember.

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17987
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I554ee0eebde93bd8f49df7f84b74acb21edcb99c
Gerrit-Change-Number: 17987
Gerrit-PatchSet: 2
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220211/83ccc2fb/attachment-0001.html>


More information about the asterisk-code-review mailing list