"""Helper methods.""" from lib import constants from lib.utils import event, ows PARENT_TABLE_NAME = 'statement_period_adjustment_file' def get_event_from_params(dag_run, **kwargs): """Get event from params passed to task callbacks.""" abacus_event = event.get_abacus_event(dag_run, **kwargs) event.validate_event_for_handler( abacus_event, target_type=constants.DAG_APPLY_PENDING_ADJUSTMENTS_TARGET_TYPE, event_name=constants.DAG_APPLY_PENDING_ADJUSTMENTS_EVENT_NAME ) 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 statement_period_adjustment_file_id (int): id of the statement_period_adjustment_file Returns: the specified action details """ # noqa: E501 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