Ar
10/03/2025, 4:12 PMkapa.ai
10/03/2025, 4:12 PMkapa.ai
10/03/2025, 4:13 PMpython from datetime import datetime import os from airflow import DAG from airflow.operators.bash_operator import BashOperator with DAG( dag_id='dbt_edr_dag', start_date=datetime(2022, 9, 1), description='An Airflow DAG to invoke dbt and Elementary commands', schedule_interval='0 0 * * *', # Adjust as needed ) as dag: dbt_run = BashOperator( task_id='dbt_run', bash_command=f"dbt run --profiles-dir {os.getenv('DBT_PROFILES_DIR')}" ) dbt_test = BashOperator( task_id='dbt_test', bash_command=f"dbt test --profiles-dir {os.getenv('DBT_PROFILES_DIR')}" ) edr_monitor = BashOperator( task_id='elementary_monitor', bash_command=f"edr monitor --profiles-dir {os.getenv('DBT_PROFILES_DIR')} --slack-token {os.getenv('SLACK_TOKEN')} --slack-channel-name {os.getenv('EDR_SLACK_CHANNEL')}" ) dbt_run >> dbt_test >> edr_monitor - Make sure the Airflow environment has access to the profiles.yml file and the necessary credentials. - You can also use the edr monitor send-report command to generate and send reports, for example to Slack or to a file. - If you use Docker with Airflow, you can use the Elementary Docker image to run these commands in a containerized environment. This approach allows you to schedule Elementary to run after your dbt jobs, ensuring that monitoring and reporting are always up-to-date with your latest data pipeline runs. You can adjust the schedule and commands as needed for your workflow and reporting preferences. For more details and examples, see the guidance and code samples provided by the Elementary team in their documentation and Slack support threads: [Elementary in production](https://docs.elementary-data.com/oss/deployment-and-configuration/elementary-in-production), [Airflow integration example](https://slack.com/archives/C02CTC89LAX/p1662015570988829), and [Cloud Airflow integration](https://docs.elementary-data.com/cloud/integrations/transformation-and-orchestration/airflow).