Created
April 5, 2014 03:04
-
-
Save rochacon/9986953 to your computer and use it in GitHub Desktop.
Simple script to consume every "celery.backend_cleanup" task from a queue
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
""" | |
This script cleans up celery.backend_cleanup task from a queue. | |
Different tasks will be printed and returned to the queue | |
""" | |
import kombu | |
AMQP_ENDPOINT = 'amqp://guest:guest@localhost:5672/vhost' | |
AMQP_QUEUE = 'celery' | |
def consume_messages(): | |
conn = kombu.Connection(AMQP_ENDPOINT) | |
q = kombu.Queue(AMQP_QUEUE, channel=conn.channel()) | |
tasks = list() | |
while True: | |
m = q.get(no_ack=False) | |
if m is None: | |
break | |
d = m.decode() | |
# ack celery.backend_cleanup tasks (removing it from the queue) | |
if d['task'] == 'celery.backend_cleanup': | |
m.ack() | |
else: | |
tasks.append(d) | |
conn.close() | |
return tasks | |
if __name__ == '__main__': | |
tasks = consume_messages() | |
for t in tasks: | |
print(t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment