def process_instruction_file(cls, file_to_process): processed = False files_fetched = [] with open(file_to_process, "r") as file_: info_file = json.load(file_) # get full_id req_id = info_file.get("req_id") hostname = info_file.get("hostname") full_id = req_id + hostname file_expired = cls.check_file_age(file_to_process) if file_expired: msg = ("%s instruction file discarded " "because it is over expiration date " "according to keepfiletime settings " "parameter" % file_to_process) LOGGER.warning(msg) Database.update_field_by_query("requestStatus", REQ_STATUS.failed, **dict(fullrequestId=full_id)) Database.update_field_by_query("message", msg, **dict(fullrequestId=full_id)) else: # get URI uri = info_file.get("uri") # fetch files on staging post processed, files_fetched = cls.fetch_files(req_id, hostname, uri) # if a file couldn't be gathered, dissemination is failed and # instruction file deleted if not processed: LOGGER.error("Couldn't fetch files from openwis staging post for" " instruction file %s." " Proceeding to next instruction file.", file_to_process) # check if database status is at failed. If yes, instruction file is deleted. # if not, it sent back to A repertory to be processed again if Database.get_request_status(full_id) == REQ_STATUS.failed: Tools.remove_file(file_to_process, "instruction", LOGGER) else: shutil.move(file_to_process, cls.dir_a) else: msg = "Instruction file %s processed" % file_to_process LOGGER.info(msg) Database.update_field_by_query("message", msg, **dict(fullrequestId=full_id)) return processed, info_file, files_fetched
def test_database_status(self): """ This tests check that the Database is currectly set up and its initial status is ONGOING """ test_diffusion = self.factory.MailDiffusion(address="*****@*****.**", headerLine="dummyHeaderLine", subject= "dummySubject", dispatchMode = "TO", attachmentMode="AS_ATTACHMENT") info = self.factory.DisseminationInfo(priority=5,SLA=6, dataPolicy="dummyDataPolicy", diffusion=test_diffusion) result = self.client.service.disseminate(requestId="123456", fileURI=self.staging_post, disseminationInfo=info) self.assertEqual(Database.get_request_status(Database.get_id_by_query()), REQ_STATUS.ongoing)