Created
November 15, 2012 18:05
-
-
Save hassek/4080169 to your computer and use it in GitHub Desktop.
Get rabbit enqueued tasks and if rabbit is up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_rabbit_status(): | |
try: | |
conn = BrokerConnection( | |
userid=settings.BROKER_USER, | |
password=settings.BROKER_PASSWORD, | |
hostname=settings.BROKER_HOST, | |
port=settings.BROKER_PORT, | |
virtual_host=settings.BROKER_VHOST | |
) | |
conn.connect() | |
except Exception as e: | |
queue_stat = [] | |
for queue in ['fast', 'medium', 'slow', 'related']: | |
queue_stat.append({'name': queue, 'message_count': 0, 'consumer_count': 0, 'running': 0}) | |
return False, queue_stat | |
else: | |
chan = conn.channel() | |
queue_stat = [] | |
for queue in ['fast', 'medium', 'slow', 'related']: | |
name, mc, cc = chan.queue_declare(queue=queue, durable=True, exclusive=False, auto_delete=False) | |
queue_stat.append({'name': name, 'message_count': mc, 'consumer_count': cc, 'running': 0}) | |
conn.release() | |
return True, queue_stat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment