CC-5990, CC-5991 - Python cleanup, removed need for /usr/lib/airtime
This commit is contained in:
parent
cd102b984b
commit
875a9dfd8b
115 changed files with 248 additions and 212 deletions
27
python_apps/media-monitor/mm2/media/monitor/eventdrainer.py
Normal file
27
python_apps/media-monitor/mm2/media/monitor/eventdrainer.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import socket
|
||||
import time
|
||||
from log import Loggable
|
||||
from toucher import RepeatTimer
|
||||
from amqplib.client_0_8.exceptions import AMQPConnectionException
|
||||
|
||||
class EventDrainer(Loggable):
|
||||
"""
|
||||
Flushes events from RabbitMQ that are sent from airtime every
|
||||
certain amount of time
|
||||
"""
|
||||
def __init__(self, airtime_notifier, interval=1):
|
||||
def cb():
|
||||
try:
|
||||
message = airtime_notifier.simple_queue.get(block=True)
|
||||
airtime_notifier.handle_message(message.payload)
|
||||
message.ack()
|
||||
except (IOError, AttributeError, AMQPConnectionException), 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
|
||||
t.start()
|
Loading…
Add table
Add a link
Reference in a new issue