From f6369c02ee4e15a0b22ad0791620d4ae6e61f5ea Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Wed, 2 Apr 2014 16:47:24 -0400 Subject: [PATCH 1/2] CC-5709: Airtime Analyzer * Catch bad callback_url --- .../airtime_analyzer/airtime_analyzer/message_listener.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py b/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py index c5e4da373..e9f5cd046 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py @@ -116,8 +116,9 @@ class MessageListener: # TODO: If the JSON was invalid or the web server is down, # then don't report that failure to the REST API #TODO: Catch exceptions from this HTTP request too: - StatusReporter.report_failure_to_callback_url(callback_url, api_key, import_status=2, - reason=u'An error occurred while importing this file') + if callback_url: # If we got an invalid message, there might be no callback_url in the JSON + StatusReporter.report_failure_to_callback_url(callback_url, api_key, import_status=2, + reason=u'An error occurred while importing this file') else: From 2a172afe3e00131bd9ab74a3b9252b61614eabcd Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Wed, 2 Apr 2014 16:51:38 -0400 Subject: [PATCH 2/2] CC-5709: Even more slightly better exception handling --- .../airtime_analyzer/airtime_analyzer/message_listener.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py b/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py index e9f5cd046..41d6f7bd2 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py @@ -74,6 +74,14 @@ class MessageListener: @staticmethod def msg_received_callback(channel, method_frame, header_frame, body): logging.info(" - Received '%s' on routing_key '%s'" % (body, method_frame.routing_key)) + + #Declare all variables here so they exist in the exception handlers below, no matter what. + audio_file_path = "" + #final_file_path = "" + import_directory = "" + original_filename = "" + callback_url = "" + api_key = "" # Spin up a worker process. We use the multiprocessing module and multiprocessing.Queue # to pass objects between the processes so that if the analyzer process crashes, it does not