forked from cockpit-project/bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspect-queue
executable file
·55 lines (45 loc) · 1.92 KB
/
inspect-queue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
# This file is part of Cockpit.
#
# Copyright (C) 2018 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
MAX_PRIORITY = 9
import argparse
import sys
from task import distributed_queue
def main():
parser = argparse.ArgumentParser(description='Read and print messages from the queue without acknowleding them')
parser.add_argument('--amqp', default='localhost:5671',
help='The host:port of the AMQP server to consume from (default: %(default)s)')
opts = parser.parse_args()
with distributed_queue.DistributedQueue(opts.amqp, ['public', 'rhel'], passive=True) as q:
def print_queue(queue):
if q.declare_results[queue] is None:
print("queue {} does not exist".format(queue))
return
message_count = q.declare_results[queue].method.message_count
if message_count == 0:
print("queue {} is empty".format(queue))
return
for i in range(message_count):
method_frame, header_frame, body = q.channel.basic_get(queue=queue)
if method_frame:
print(body.decode())
print('public queue:')
print_queue('public')
print('rhel queue:')
print_queue('rhel')
if __name__ == '__main__':
sys.exit(main())