Skip to content

Instantly share code, notes, and snippets.

@scisco
Created May 11, 2016 19:19
Show Gist options
  • Save scisco/ec359da9544798fd7e19ce2d2aaa7099 to your computer and use it in GitHub Desktop.
Save scisco/ec359da9544798fd7e19ce2d2aaa7099 to your computer and use it in GitHub Desktop.
rabbitmq queue clean up
import json
import pika
url = 'amqp://url/'
connection = pika.BlockingConnection(pika.URLParameters(url))
channel = connection.channel()
while True:
method_frame, header_frame, body = channel.basic_get('default')
if method_frame:
if method_frame.message_count < 1000:
break
else:
print(method_frame.message_count)
body = json.loads(body.decode('utf8'))
if body['task'] == 'plans.tasks.calculate_task_totals' or body['task'] == 'plans.tasks.calculate_aoi_totals':
print('discarded')
channel.basic_ack(method_frame.delivery_tag)
else:
print(body)
else:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment