"""Invoke commit royalties lambda task method.""" from hooks.lambda_hook import OrchLambdaHook from lib import config from lib import constants from tasks.accounting_run_commit import helpers def invoke_commit_royalties_lambda_task(dag_run: dict, *args, **kwargs) -> None: """Create a commit_royalties event and use it to invoke commit royalties processor. Args: dag_run (dict): a dag's config """ event = helpers.get_event_from_params(dag_run, **kwargs) accounting_run_id = event.target_id commit_royalties_event = helpers.create_event( accounting_run_id, constants.DAG_COMMIT_COMMIT_ROYALTIES_EVENT_NAME ) hook = OrchLambdaHook(config.ROYALTY_PROCESSOR_LAMBDA_NAME, invocation_type='Event') response = hook.invoke_lambda(commit_royalties_event.to_json()) if not response.function_response.succeeded: print(f'Lambda invocation not successful') print(f'Unsuccessful Response: {vars(response)}') print(f'Unsuccessful Func Response: {vars(response.function_response)}') raise Exception(response.error_message) else: helpers.create_abacus_state( accounting_run_id, constants.ACCOUNTING_RUN_ACTIONS.COMMIT_ROYALTIES )