"""Helper methods.""" from lib import constants from lib.utils import event, ows PARENT_TABLE_NAME = 'statement_period' 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_ADJUSTMENTS_TARGET_TYPE, event_name=constants.DAG_APPLY_ADJUSTMENTS_EVENT_NAME ) return abacus_event def get_abacus_state(action_name: str, statement_period_id: int) -> dict: """Find specified action in list of contract actions. Args: action_name (str): name of the action for to get details statement_period_id (int): ID of the statement_period Returns: the specified action details """ abacus_states = ows.get_abacus_states(PARENT_TABLE_NAME, statement_period_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