Another small bugfix for error handling in the analyzer
This commit is contained in:
parent
492a7f329a
commit
d5012c25cb
2 changed files with 9 additions and 7 deletions
|
@ -22,6 +22,8 @@ class AnalyzerPipeline:
|
||||||
the failure to import can be reported back to the web application.
|
the failure to import can be reported back to the web application.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
IMPORT_STATUS_FAILED = 2
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run_analysis(queue, audio_file_path, import_directory, original_filename, storage_backend, file_prefix, cloud_storage_config):
|
def run_analysis(queue, audio_file_path, import_directory, original_filename, storage_backend, file_prefix, cloud_storage_config):
|
||||||
"""Analyze and import an audio file, and put all extracted metadata into queue.
|
"""Analyze and import an audio file, and put all extracted metadata into queue.
|
||||||
|
@ -86,7 +88,7 @@ class AnalyzerPipeline:
|
||||||
queue.put(metadata)
|
queue.put(metadata)
|
||||||
except UnplayableFileError as e:
|
except UnplayableFileError as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
metadata["import_status"] = 2
|
metadata["import_status"] = IMPORT_STATUS_FAILED
|
||||||
metadata["reason"] = "The file could not be played."
|
metadata["reason"] = "The file could not be played."
|
||||||
raise e
|
raise e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -226,19 +226,19 @@ class MessageListener:
|
||||||
else:
|
else:
|
||||||
raise Exception("Analyzer process terminated unexpectedly.")
|
raise Exception("Analyzer process terminated unexpectedly.")
|
||||||
'''
|
'''
|
||||||
results = {}
|
metadata = {}
|
||||||
|
|
||||||
q = Queue.Queue()
|
q = Queue.Queue()
|
||||||
try:
|
try:
|
||||||
AnalyzerPipeline.run_analysis(q, audio_file_path, import_directory, original_filename, storage_backend, file_prefix, cloud_storage_config)
|
AnalyzerPipeline.run_analysis(q, audio_file_path, import_directory, original_filename, storage_backend, file_prefix, cloud_storage_config)
|
||||||
results = q.get()
|
metadata = q.get()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Analyzer pipeline exception: %s" % str(e))
|
logging.error("Analyzer pipeline exception: %s" % str(e))
|
||||||
pass
|
metadata["import_status"] = AnalyzerPipeline.IMPORT_STATUS_FAILED
|
||||||
|
|
||||||
# Ensure our queue doesn't fill up and block due to unexpected behaviour. Defensive code.
|
# Ensure our queue doesn't fill up and block due to unexpected behaviour. Defensive code.
|
||||||
while not q.empty():
|
while not q.empty():
|
||||||
q.get()
|
q.get()
|
||||||
|
|
||||||
return results
|
return metadata
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue