From e1dd6f06d9fce10a567bf719d3695727c0d0c059 Mon Sep 17 00:00:00 2001 From: Ivan Tyagov <ivan@nexedi.com> Date: Mon, 4 May 2020 16:47:09 +0300 Subject: [PATCH] Handling any exception to log is bad as you already have error_log. --- .../ingestionReferenceExists.py | 98 +++++++++---------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/bt5/erp5_wendelin_data_lake_ingestion/SkinTemplateItem/portal_skins/erp5_wendelin_data_lake/ingestionReferenceExists.py b/bt5/erp5_wendelin_data_lake_ingestion/SkinTemplateItem/portal_skins/erp5_wendelin_data_lake/ingestionReferenceExists.py index bee97ca..a0e5b22 100644 --- a/bt5/erp5_wendelin_data_lake_ingestion/SkinTemplateItem/portal_skins/erp5_wendelin_data_lake/ingestionReferenceExists.py +++ b/bt5/erp5_wendelin_data_lake_ingestion/SkinTemplateItem/portal_skins/erp5_wendelin_data_lake/ingestionReferenceExists.py @@ -14,54 +14,50 @@ reference_separator = portal.getIngestionReferenceDictionary()["reference_separa reference_end_single = portal.getIngestionReferenceDictionary()["single_end_suffix"] reference_end_split = portal.getIngestionReferenceDictionary()["split_end_suffix"] -try: - # remove supplier and eof from reference - data_ingestion_reference = reference_separator.join(reference.split(reference_separator)[1:-3]) - EOF = reference.split(reference_separator)[-3] - size = reference.split(reference_separator)[-2] - - if data_ingestion_reference is "": - context.logEntry("[ERROR] Data Ingestion reference parameter for ingestionReferenceExists script is not well formated") - raise ValueError("Data Ingestion reference is not well formated") - - # check if there are started ingestions for this reference - data_ingestion = portal_catalog.getResultValue( - portal_type = 'Data Ingestion', - simulation_state = "started", - reference = data_ingestion_reference) - if data_ingestion != None: - try: - # check if user tries to restart the previous split ingestion - if (EOF == "" or EOF == reference_end_single) or (EOF != reference_end_split and int(EOF) == 1): - # check if existing split ingestion is still being processed or if it is interrumped - data_ingestion_eof = portal_catalog.getResultValue( - portal_type = 'Data Ingestion', - reference = data_ingestion_reference, - id = "%" + reference_end_split) - if data_ingestion_eof: - # reference exists: previous split ingestion is still being processed - return TRUE - else: - # previous ingestion was interrumped - log(''.join(["[WARNING] User has restarted an interrumpted ingestion for reference ", data_ingestion.getReference(), ". Previous split ingestions will be discarted and full ingestion restarted."])) - portal.ERP5Site_invalidateSplitIngestions(data_ingestion.getReference(), success=False) - except: - pass - # the ingestion attemp corresponds to a split ingestion in course, accept - return FALSE - - data_ingestion = portal_catalog.getResultValue( - portal_type = 'Data Ingestion', - reference = data_ingestion_reference) - - if data_ingestion is None: - return FALSE - - # TODO: fix this (contemplate scenarios of partial ingestion overwrites) - if size != "" and size != None: - # this is a modified file - return FALSE - return TRUE -except Exception as e: - context.logEntry(''.join(["[ERROR] At script ingestionReferenceExists: ", str(e)])) - raise e +# remove supplier and eof from reference +data_ingestion_reference = reference_separator.join(reference.split(reference_separator)[1:-3]) +EOF = reference.split(reference_separator)[-3] +size = reference.split(reference_separator)[-2] + +if data_ingestion_reference is "": + context.logEntry("[ERROR] Data Ingestion reference parameter for ingestionReferenceExists script is not well formated") + raise ValueError("Data Ingestion reference is not well formated") + +# check if there are started ingestions for this reference +data_ingestion = portal_catalog.getResultValue( + portal_type = 'Data Ingestion', + simulation_state = "started", + reference = data_ingestion_reference) +if data_ingestion != None: + try: + # check if user tries to restart the previous split ingestion + if (EOF == "" or EOF == reference_end_single) or (EOF != reference_end_split and int(EOF) == 1): + # check if existing split ingestion is still being processed or if it is interrumped + data_ingestion_eof = portal_catalog.getResultValue( + portal_type = 'Data Ingestion', + reference = data_ingestion_reference, + id = "%" + reference_end_split) + if data_ingestion_eof: + # reference exists: previous split ingestion is still being processed + return TRUE + else: + # previous ingestion was interrumped + log(''.join(["[WARNING] User has restarted an interrumpted ingestion for reference ", data_ingestion.getReference(), ". Previous split ingestions will be discarted and full ingestion restarted."])) + portal.ERP5Site_invalidateSplitIngestions(data_ingestion.getReference(), success=False) + except: + pass + # the ingestion attemp corresponds to a split ingestion in course, accept + return FALSE + +data_ingestion = portal_catalog.getResultValue( + portal_type = 'Data Ingestion', + reference = data_ingestion_reference) + +if data_ingestion is None: + return FALSE + +# TODO: fix this (contemplate scenarios of partial ingestion overwrites) +if size != "" and size != None: + # this is a modified file + return FALSE +return TRUE -- 2.30.9