"""Check adjustment_file error report exist or not.""" from lib import constants from lib.utils import aws from lib.utils import ows from tasks.adjustment_file_upload import helpers def check_adjustment_file_error_report_task(dag_run, *arg, **kwargs): """Check if error report exist for uploaded adjustment file.""" event = helpers.get_event_from_params(dag_run, **kwargs) adjustment_file_details = ows.get_statement_period_adjustment_file_details( event.target_id ) adjustment_invalid_file_location = \ adjustment_file_details.get('invalid_file_location') error_type = adjustment_file_details.get('error_type') if adjustment_invalid_file_location and \ aws.file_exists(adjustment_invalid_file_location) and \ error_type == 'content_error': raise Exception( 'An error report has been generated for the uploaded adjustment file.' ) if not adjustment_invalid_file_location and error_type == 'content_error': raise Exception( 'There is an error while generating the adjustment file error report. Please check the lambda logs.' # noqa: E501 ) action_name = constants.STATEMENT_PERIOD_ADJUSTMENT_FILE_ACTIONS.UPLOAD_FILE action_status = helpers.get_abacus_state(action_name, event.target_id) if action_status.get('action_status') == constants.ABACUS_STATE_STATUSES.ERROR: # noqa: E501 raise Exception( 'There is an error while validating the adjustment file. Please check the lambda logs.' # noqa: E501 )