Merge branch 'cc-5709-airtime-analyzer' into cc-5709-airtime-analyzer-saas

Conflicts:
	airtime_mvc/locale/de_DE/LC_MESSAGES/airtime.po
	airtime_mvc/locale/es_ES/LC_MESSAGES/airtime.po
This commit is contained in:
Albert Santoni 2014-04-09 15:01:11 -04:00
commit 8fb95316f2
27 changed files with 52765 additions and 54545 deletions

View file

@ -4,6 +4,7 @@ import ConfigParser
import logging
import logging.handlers
import sys
from functools import partial
from metadata_analyzer import MetadataAnalyzer
from replaygain_analyzer import ReplayGainAnalyzer
from message_listener import MessageListener
@ -26,7 +27,7 @@ class AirtimeAnalyzerServer:
# Read our config file
rabbitmq_config = self.read_config_file(config_path)
# Start listening for RabbitMQ messages telling us about newly
# uploaded files.
self._msg_listener = MessageListener(rabbitmq_config)
@ -74,4 +75,4 @@ class AirtimeAnalyzerServer:
exit(-1)
return config

View file

@ -2,6 +2,8 @@ import sys
import pika
import json
import time
import select
import signal
import logging
import multiprocessing
from analyzer_pipeline import AnalyzerPipeline
@ -59,6 +61,8 @@ class MessageListener:
Keyword arguments:
config: A ConfigParser object containing the [rabbitmq] configuration.
'''
self._shutdown = False
# Read the RabbitMQ connection settings from the config file
# The exceptions throw here by default give good error messages.
@ -68,21 +72,31 @@ class MessageListener:
self._username = config.get(RMQ_CONFIG_SECTION, 'user')
self._password = config.get(RMQ_CONFIG_SECTION, 'password')
self._vhost = config.get(RMQ_CONFIG_SECTION, 'vhost')
# Set up a signal handler so we can shutdown gracefully
# For some reason, this signal handler must be set up here. I'd rather
# put it in AirtimeAnalyzerServer, but it doesn't work there (something to do
# with pika's SIGTERM handler interfering with it, I think...)
signal.signal(signal.SIGTERM, self.graceful_shutdown)
while True:
while not self._shutdown:
try:
self.connect_to_messaging_server()
self.wait_for_messages()
except KeyboardInterrupt:
self.disconnect_from_messaging_server()
break
except (KeyboardInterrupt, SystemExit):
break # Break out of the while loop and exit the application
except select.error:
pass
except pika.exceptions.AMQPError as e:
if self._shutdown:
break
logging.error("Connection to message queue failed. ")
logging.error(e)
logging.info("Retrying in 5 seconds...")
time.sleep(5)
self._connection.close()
self.disconnect_from_messaging_server()
logging.info("Exiting cleanly.")
def connect_to_messaging_server(self):
@ -107,7 +121,12 @@ class MessageListener:
def disconnect_from_messaging_server(self):
'''Stop consuming RabbitMQ messages and disconnect'''
self._channel.stop_consuming()
self._connection.close()
def graceful_shutdown(self, signum, frame):
'''Disconnect and break out of the message listening loop'''
self._shutdown = True
self.disconnect_from_message_listener()
@staticmethod
def msg_received_callback(channel, method_frame, header_frame, body):