From 05396e9213122dd1beba6cad017f07fef898f06e Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 26 Feb 2015 21:13:37 -0500 Subject: [PATCH] collecting MTURK_HOST test and fixing it. closes #408 --- karmaworld/apps/quizzes/tasks.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/karmaworld/apps/quizzes/tasks.py b/karmaworld/apps/quizzes/tasks.py index 979e2e7..bcd9604 100644 --- a/karmaworld/apps/quizzes/tasks.py +++ b/karmaworld/apps/quizzes/tasks.py @@ -92,15 +92,23 @@ KEYWORDS_HIT_DEFINITION_FIELDS = [ ('definition20', 'Definition 20'), ] +def run_mturk(whence): + try: + MTURK_HOST = os.environ['MTURK_HOST'] + except KeyError, e: + logger.warn('Not running {0}: could not find Mechanical Turk secrets' + .format(whence)) + return '' + else: + return MTURK_HOST + @task(name='submit_extract_keywords_hit') def submit_extract_keywords_hit(note): """Create a Mechanical Turk HIT that asks a worker to choose keywords and definitions from the given note.""" - try: - MTURK_HOST = os.environ['MTURK_HOST'] - except: - logger.warn('Could not find Mechanical Turk secrets, not running submit_extract_keywords_hit') + MTURK_HOST = run_mturk('submit_extract_keywords_hit') + if not MTURK_HOST: return connection = MTurkConnection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, @@ -154,10 +162,8 @@ def submit_extract_keywords_hit(note): @task(name='get_extract_keywords_results') def get_extract_keywords_results(): - try: - MTURK_HOST = os.environ['MTURK_HOST'] - except ImportError: - logger.warn('Could not find Mechanical Turk secrets, not running get_extract_keywords_results') + MTURK_HOST = run_mturk('get_extract_keywords_results') + if not MTURK_HOST: return connection = MTurkConnection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, @@ -239,11 +245,14 @@ CONTENT_DISPOSITION_REGEX = r'filename="(?P.+)"' @task(name='check_notes_mailbox') def check_notes_mailbox(): + MTURK_HOST = run_mturk('get_extract_keywords_results') + if not MTURK_HOST: + return + try: MAILBOX_USER = os.environ['NOTES_MAILBOX_USERNAME'] MAILBOX_PASSWORD = os.environ['NOTES_MAILBOX_PASSWORD'] FILEPICKER_API_KEY = os.environ['FILEPICKER_API_KEY'] - MTURK_HOST = os.environ['MTURK_HOST'] except: logger.warn('Could not find notes mailbox secrets, not running check_notes_mailbox') return -- 2.25.1