show-queues: A script to display a summary of what's in the queues.
authorRichard W.M. Jones <rjones@redhat.com>
Fri, 7 Jul 2017 13:30:22 +0000 (14:30 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Fri, 7 Jul 2017 13:30:22 +0000 (14:30 +0100)
show-queues.py [new file with mode: 0755]

diff --git a/show-queues.py b/show-queues.py
new file mode 100755 (executable)
index 0000000..9a8b4f0
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Display the contents of the queues.
+#
+# Note this cannot display messages which are being processed.
+#
+# This works by fetching the messages without acknowledging them,
+# effectively peeking into the queues.
+
+import email
+import json
+import pika
+
+import config
+
+connection = pika.BlockingConnection(pika.ConnectionParameters(
+    host = config.mq_server))
+channel = connection.channel()
+
+print "patchq_input (Unordered messages):"
+while True:
+    method, _, body = channel.basic_get(queue = 'patchq_input', no_ack = False)
+    if not method: break
+    m = email.message_from_string(body) # the email
+    # Only display the subject line.
+    print ("    %s" % m['Subject'])
+
+for t in config.tests:
+    qname = "patchq_test_%s" % t
+    print ("%s (Threads queued for %s):" % (qname, t))
+    while True:
+        method, _, body = channel.basic_get(queue = qname, no_ack = False)
+        if not method: break
+
+        msgs = json.loads(body)
+        msgs = [email.message_from_string(m) for m in msgs]
+
+        print ("    Thread:")
+        for m in msgs:
+            print ("        %s" % m['Subject'])
+
+print "patchq_reports (Reports):"
+while True:
+    method, _, _ = channel.basic_get(queue = 'patchq_reports', no_ack = False)
+    if not method: break
+
+    to, subject, ref, content = json.loads(body)
+
+    print ("    %s" % subject)
+
+print
+print "Note that messages being processed are not displayed.  To see all"
+print "messages use ‘rabbitmqctl list_queues’ and other RabbitMQ admin tools."