"""Helper methods.""" from lib import constants from lib.utils import event, ows 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_RESERVES_RELEASE_TARGET_TYPE, event_name=constants.DAG_RESERVES_RELEASE_EVENT_NAME ) return abacus_event def get_action_state(statement_period_id, action_name): """Request abacus state.""" abacus_state = ows.get_abacus_states('statement-period', statement_period_id) action = list( filter(lambda x: x['action_name'] == action_name, abacus_state) ) if not action: raise ValueError('{} state not found'.format(action_name)) return action[0]