"""Task to export mechanical deduction results to S3 for HFA.""" from hooks.royalty_snowflake_hook import RoyaltySnowflakeHook from lib import config from lib.utils import ows from tasks.accounting_run_commit.helpers import build_mechanical_export_location from tasks.accounting_run_commit.helpers import get_event_from_params from templates.accounting_run_commit.snowflake_export_mech_deductions \ import export_mechanical_deductions_to_s3 def export_mechanicals_task(dag_run: dict, **kwargs) -> None: """Export mech deduction results to S3 as TSV for HFA. Args: dag_run (dict): the dag's config """ event = get_event_from_params(dag_run, **kwargs) accounting_run_id = event.target_id accounting_run = ows.get_accounting_run_details(accounting_run_id) accounting_period_id = accounting_run.get('accounting_period_id') accounting_period = ows.get_accounting_period_details(accounting_period_id) s3_location = build_mechanical_export_location(accounting_period, accounting_run) hook = RoyaltySnowflakeHook(snowflake_conn_id=config.SNOWFLAKE_CONN_NAME) export_statement = export_mechanical_deductions_to_s3().render( accounting_run_id=accounting_run_id, s3_path=s3_location.key, schema=config.OWS_ENV, stage=config.ABACUS_TSV_STAGE ) hook.run(export_statement, autocommit=True)