Created
May 11, 2016 19:19
-
-
Save scisco/ec359da9544798fd7e19ce2d2aaa7099 to your computer and use it in GitHub Desktop.
rabbitmq queue clean up
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
| 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