"""Check response from commit royalties lambda task method.""" from lib import constants from tasks.accounting_run_commit import helpers def commit_royalties_lambda_response_check(dag_run: dict, **kwargs) -> bool: """Check a status of abacus_state for commit_royalties process. Args: dag_run (dict): a dag's config Returns: True when action_status = `complete` False when action_status has other value than `complete` or `error` Raises: Exception: when action_status = `error`. """ event = helpers.get_event_from_params(dag_run, **kwargs) accounting_run_id = event.target_id abacus_state = helpers.get_abacus_state(accounting_run_id) abacus_state_status = abacus_state.action_status if abacus_state_status == constants.ABACUS_STATE_STATUSES.COMPLETE: return True elif abacus_state_status == constants.ABACUS_STATE_STATUSES.ERROR: raise Exception(f'Commit_royalties lambda failed, ' f'message: {abacus_state.message}') else: return False