def do_activity(self, data=None): """ Do the work """ if self.logger: self.logger.info('data: %s' % json.dumps(data, sort_keys=True, indent=4)) ########### if not self.settings.consider_Lax_elife_2_0: if self.logger: self.logger.info('PublishToLax. Lax is not being considered. Skipping activity.') return True ########### article_id = data['article_id'] version = data['version'] run = data['run'] workflow_data = self.get_workflow_data(data) status = workflow_data['status'] eif_location = workflow_data['eif_location'] expanded_folder = workflow_data['expanded_folder'] self.emit_monitor_event(self.settings, article_id, version, run, "Publish To Lax", "start", "Starting preparation of article for Lax " + article_id) try: force = True if ("force" in data and data["force"] == True) else False message = lax_provider.prepare_action_message(self.settings, article_id, run, expanded_folder, version, status, eif_location, 'publish', force) message_body = json.dumps(message) self.logger.info("Sending message to lax: %s", message_body) sqs_conn = boto.sqs.connect_to_region( self.settings.sqs_region, aws_access_key_id=self.settings.aws_access_key_id, aws_secret_access_key=self.settings.aws_secret_access_key) out_queue = sqs_conn.get_queue(self.settings.xml_info_queue) m = RawMessage() m.set_body(message_body) out_queue.write(m) ######### except Exception as e: self.logger.exception("Exception when Preparing Publish action for Lax") self.emit_monitor_event(self.settings, article_id, version, run, "Publish To Lax", "error", "Error preparing or sending message to lax" + article_id + " message:" + str(e.message)) return False self.emit_monitor_event(self.settings, article_id, version, run, "Publish To Lax", "end", "Finished preparation of article for Lax " + article_id) return True
def test_prepare_action_message(self, fake_xml_file_name): fake_xml_file_name.return_value = "elife-00353-v1.xml" message = lax_provider.prepare_action_message(settings_mock, "00353", "bb2d37b8-e73c-43b3-a092-d555753316af", "00353.1/bb2d37b8-e73c-43b3-a092-d555753316af", "1", "vor", "", "ingest") self.assertIn('token', message) del message['token'] self.assertDictEqual(message, {'action': 'ingest', 'id': '00353', 'location': 'https://s3-external-1.amazonaws.com/origin_bucket/00353.1/bb2d37b8-e73c-43b3-a092-d555753316af/elife-00353-v1.xml', 'version': 1, 'force': False})
def test_prepare_action_message(self, fake_xml_file_name): fake_xml_file_name.return_value = "elife-00353-v1.xml" message = lax_provider.prepare_action_message( settings_mock, "00353", "bb2d37b8-e73c-43b3-a092-d555753316af", "00353.1/bb2d37b8-e73c-43b3-a092-d555753316af", "1", "vor", "", "ingest") self.assertIn('token', message) del message['token'] self.assertDictEqual( message, { 'action': 'ingest', 'id': '00353', 'location': 'https://s3-external-1.amazonaws.com/origin_bucket/00353.1/bb2d37b8-e73c-43b3-a092-d555753316af/elife-00353-v1.xml', 'version': 1, 'force': False })
def get_message_queue(self, data=None, consider_elife_20=True): """ Do the work """ if self.logger: self.logger.info('data: %s' % json.dumps(data, sort_keys=True, indent=4)) run = data['run'] version = data['version'] article_id = data['article_id'] status = data['status'] eif_location = "" #not available yet try: expanded_folder = data['expanded_folder'] ########## if not consider_elife_20: start_event = [self.settings, article_id, version, run, self.pretty_name + " (Skipping)", "start", "Starting preparation of article " + article_id] try: workflow_starter_message = { "workflow_name": "ProcessArticleZip", "workflow_data": { "run":run , "article_id": article_id, "result": "", "status": status, "version": version, "expanded_folder": expanded_folder, "eif_location": "", "requested_action": "", "message": "", "update_date": data['update_date'] } } return (workflow_starter_message, self.settings.workflow_starter_queue,start_event, "end", [self.settings, article_id, version, run, self.pretty_name + " (Skipping)", "end", "Lax is not being considered, this activity just triggered next " "workflow without influence from Lax."], None) except Exception as e: return (None, None, start_event, "error", [self.settings, article_id, version, run, self.pretty_name + " (Skipping)", "error", "An error has occurred. Details: %s", str(e.message)], str(e.message)) ########## start_event = [self.settings, article_id, version, run, self.pretty_name, "start", "Starting preparation of article for Lax " + article_id] force = True if ("force" in data and data["force"] == True) else False message = lax_provider.prepare_action_message(self.settings, article_id, run, expanded_folder, version, status, eif_location, 'ingest', force) return (message, self.settings.xml_info_queue, start_event, "end", [self.settings, article_id, version, run, self.pretty_name, "end", "Finished preparation of article for Lax. Ingest sent to Lax" + article_id], None) except Exception as e: self.logger.exception("Exception when Preparing Ingest for Lax") return (None, None, start_event, "error", [self.settings, article_id, version, run, self.pretty_name, "error", "Error preparing or sending message to lax" + article_id + " message: " + str(e.message)], str(e.message))
def get_message_queue(self, data=None, consider_elife_20=True): """ Do the work """ if self.logger: self.logger.info('data: %s' % json.dumps(data, sort_keys=True, indent=4)) run = data['run'] version = data['version'] article_id = data['article_id'] status = data['status'] eif_location = "" #not available yet try: expanded_folder = data['expanded_folder'] ########## if not consider_elife_20: start_event = [ self.settings, article_id, version, run, self.pretty_name + " (Skipping)", "start", "Starting preparation of article " + article_id ] try: workflow_starter_message = { "workflow_name": "ProcessArticleZip", "workflow_data": { "run": run, "article_id": article_id, "result": "", "status": status, "version": version, "expanded_folder": expanded_folder, "eif_location": "", "requested_action": "", "message": "", "update_date": data['update_date'] } } return ( workflow_starter_message, self.settings.workflow_starter_queue, start_event, "end", [ self.settings, article_id, version, run, self.pretty_name + " (Skipping)", "end", "Lax is not being considered, this activity just triggered next " "workflow without influence from Lax." ], None) except Exception as e: return (None, None, start_event, "error", [ self.settings, article_id, version, run, self.pretty_name + " (Skipping)", "error", "An error has occurred. Details: %s", str(e.message) ], str(e.message)) ########## start_event = [ self.settings, article_id, version, run, self.pretty_name, "start", "Starting preparation of article for Lax " + article_id ] force = True if ("force" in data and data["force"] == True) else False message = lax_provider.prepare_action_message( self.settings, article_id, run, expanded_folder, version, status, eif_location, 'ingest', force) return (message, self.settings.xml_info_queue, start_event, "end", [ self.settings, article_id, version, run, self.pretty_name, "end", "Finished preparation of article for Lax. Ingest sent to Lax" + article_id ], None) except Exception as e: self.logger.exception("Exception when Preparing Ingest for Lax") return (None, None, start_event, "error", [ self.settings, article_id, version, run, self.pretty_name, "error", "Error preparing or sending message to lax" + article_id + " message: " + str(e.message) ], str(e.message))
def do_activity(self, data=None): """ Do the work """ if self.logger: self.logger.info('data: %s' % json.dumps(data, sort_keys=True, indent=4)) ########### if not self.settings.consider_Lax_elife_2_0: if self.logger: self.logger.info( 'PublishToLax. Lax is not being considered. Skipping activity.' ) return True ########### article_id = data['article_id'] version = data['version'] run = data['run'] workflow_data = self.get_workflow_data(data) status = workflow_data['status'] eif_location = workflow_data['eif_location'] expanded_folder = workflow_data['expanded_folder'] self.emit_monitor_event( self.settings, article_id, version, run, "Publish To Lax", "start", "Starting preparation of article for Lax " + article_id) try: force = True if ("force" in data and data["force"] == True) else False message = lax_provider.prepare_action_message( self.settings, article_id, run, expanded_folder, version, status, eif_location, 'publish', force) message_body = json.dumps(message) self.logger.info("Sending message to lax: %s", message_body) sqs_conn = boto.sqs.connect_to_region( self.settings.sqs_region, aws_access_key_id=self.settings.aws_access_key_id, aws_secret_access_key=self.settings.aws_secret_access_key) out_queue = sqs_conn.get_queue(self.settings.xml_info_queue) m = RawMessage() m.set_body(message_body) out_queue.write(m) ######### except Exception as e: self.logger.exception( "Exception when Preparing Publish action for Lax") self.emit_monitor_event( self.settings, article_id, version, run, "Publish To Lax", "error", "Error preparing or sending message to lax" + article_id + " message:" + str(e.message)) return False self.emit_monitor_event( self.settings, article_id, version, run, "Publish To Lax", "end", "Finished preparation of article for Lax " + article_id) return True