"""Helper methods.""" from lib import constants from lib.abacus_event import AbacusEvent from lib.utils import event from lib.utils import ows PARENT_TABLE_NAME = 'statement_period_adjustment_file' def get_event_from_params(dag_run: dict, **kwargs) -> AbacusEvent: """Get event from params passed to task callbacks. Args: dag_run (dict): a dag's config Returns: instance of an AbacusEvent """ abacus_event = event.get_abacus_event(dag_run, **kwargs) event.validate_event_for_handler( abacus_event, event_name=constants.DAG_ADJUSTMENT_FILE_UPLOAD_EVENT_NAME, target_type=constants.DAG_ADJUSTMENT_FILE_UPLOAD_TARGET_TYPE ) return abacus_event def get_abacus_state( action_name: str, statement_period_adjustment_file_id: int ) -> dict: """Find specified action in list of statement_period_adjustment_file actions. Args: action_name (str): name of the action for to get details statement_period_adjustment_file_id (int): ID of the statement_period_adjustment_file Returns: the specified action details """ abacus_states = ows.get_abacus_states( PARENT_TABLE_NAME, statement_period_adjustment_file_id ) action_state = next( (action for action in abacus_states if action['action_name'] == action_name), None ) if not action_state: raise ValueError(f'{action_name} state not found') return action_state