Last active
July 13, 2016 09:31
-
-
Save ygbourhis/8d258ae76d62ef11a2f77f0251c906ff to your computer and use it in GitHub Desktop.
Quick and dirty workaround for https://bugs.launchpad.net/heat/+bug/1599104
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
#!/usr/bin/env python | |
""" | |
Quick and dirty workaround for https://bugs.launchpad.net/heat/+bug/1599104 | |
add rabbitmq_management plugin: | |
sudo /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management | |
sudo service rabbitmq-server restart | |
install rabbitmqadmin which is provided by rabbitmq_management: | |
cd /usr/bin | |
sudo wget http://localhost:15672/cli/rabbitmqadmin | |
sudo chmod a+x rabbitmqadmin | |
cd | |
Or download it at http://<Your_Rabbit_MQ_server>:15672/cli/rabbitmqadmin | |
if your rabbitmq needs special credentials (it should :-) ) launch: | |
rabbitmqadmin help config | |
and create a `~/.rabbitmqadmin.conf` | |
Once done, launch this script. | |
""" | |
from datetime import datetime | |
from datetime import timedelta | |
import json | |
from shlex import split | |
from subprocess import check_output | |
DATE_FMT = '%Y-%m-%d %H:%M:%S' | |
NOW = datetime.now() | |
# same IDLE_TIME as heat-engine-listener_fanout queues | |
IDLE_TIME = timedelta(microseconds=1800000) | |
OLD_TIME = NOW - IDLE_TIME | |
LIST_QUEUES_CMD = split( | |
'rabbitmqadmin -f raw_json list queues name idle_since' | |
) | |
DELETE_QUEUE_CMD = 'rabbitmqadmin delete queue name=%s' | |
QUEUE_TO_DELETE_PREFIX = 'heat-engine-listener.' | |
strptime = datetime.strptime # gain time in huge loops | |
def is_idle(queue): | |
try: | |
return strptime(queue['idle_since'], DATE_FMT) < OLD_TIME | |
except KeyError: | |
return False | |
def del_queue(queue): | |
print 'deleting %s' % queue['name'] | |
print check_output(split(DELETE_QUEUE_CMD % queue['name'])) | |
queues = json.loads(check_output(LIST_QUEUES_CMD)) | |
for queue in queues: | |
if QUEUE_TO_DELETE_PREFIX in queue['name'] and is_idle(queue): | |
del_queue(queue) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment