"""Task to insert NR contributor, contributions, schedules into snowflake table.""" from hooks.royalty_snowflake_hook import RoyaltySnowflakeHook from lib import config from tasks.accounting_run_calculate_nr import helpers from templates.accounting_run_calculate.snowflake_snapshot_contract_term_schedules_nr \ import snapshot_contract_term_schedule_nr_template def snapshot_contract_term_schedules_nr_task(dag_run: dict, **kwargs) -> None: """Query royalty_accounting replica and insert into snowflake snapshot table. Args: dag_run (dict): config of the DAG this task belongs to kwargs (dict): any other optional arguments """ event = helpers.get_event_from_params(dag_run, **kwargs) accounting_run_id = event.target_id hook = RoyaltySnowflakeHook(snowflake_conn_id=config.SNOWFLAKE_CONN_NAME) insert_statement = snapshot_contract_term_schedule_nr_template().render( accounting_run_id=accounting_run_id, env='prod' if config.OWS_ENV.lower() == 'prod' else 'qa', schema=config.OWS_ENV ) hook.run(insert_statement, autocommit=True)