"""Task to cleanup snowflake by truncating temp sales.""" from hooks.royalty_snowflake_hook import RoyaltySnowflakeHook from lib import config from lib.constants import STMT_DB_SALES_TEMP_TABLES from lib.utils import ows from tasks.accounting_period_sales_approve.helpers import get_event_from_params from templates.accounting_period_sales_approve.snowflake_truncate_temp_sales\ import truncate_temp_sales def truncate_temp_sales_task(dag_run: dict, **kwargs) -> None: """Truncate records from stmt_db_sale_*_temp. Args: dag_run (dict): config of the DAG this task belongs to kwargs (dict): any other optional arguments """ event = get_event_from_params(dag_run, **kwargs) accounting_period_id = event.target_id accounting_period = ows.get_accounting_period_details( accounting_period_id ) contract_type = accounting_period['contract_type'] hook = RoyaltySnowflakeHook(snowflake_conn_id=config.SNOWFLAKE_CONN_NAME) truncate_statement = truncate_temp_sales().render( env=config.OWS_ENV, temp_table=STMT_DB_SALES_TEMP_TABLES[contract_type] ) hook.run(truncate_statement, autocommit=True)