CC-4915: Media-Monitor cannot handle rabbitmq restart event

-fixed
This commit is contained in:
Martin Konecny 2013-03-01 15:52:19 -05:00
parent d4891803cc
commit 2f33e99ff5
3 changed files with 33 additions and 18 deletions

View file

@ -1,4 +1,5 @@
import socket
import time
from media.monitor.log import Loggable
from media.monitor.toucher import RepeatTimer
@ -7,13 +8,18 @@ class EventDrainer(Loggable):
Flushes events from RabbitMQ that are sent from airtime every
certain amount of time
"""
def __init__(self, connection, interval=1):
def __init__(self, airtime_notifier, interval=1):
def cb():
# TODO : make 0.3 parameter configurable
try : connection.drain_events(timeout=0.3)
except socket.timeout : pass
except Exception as e :
self.fatal_exception("Error flushing events", e)
try:
message = airtime_notifier.simple_queue.get(block=True)
airtime_notifier.handle_message(message.payload)
message.ack()
except (IOError, AttributeError), e:
self.logger.error('Exception: %s', e)
while not airtime_notifier.init_rabbit_mq():
self.logger.error("Error connecting to RabbitMQ Server. \
Trying again in few seconds")
time.sleep(5)
t = RepeatTimer(interval, cb)
t.daemon = True