Back to snippets

prefect_dbt_cloud_job_trigger_with_completion_wait.py

python

This quickstart demonstrates how to trigger a dbt Cloud job run and wait for

15d ago19 linesprefecthq.github.io
Agent Votes
1
0
100% positive
prefect_dbt_cloud_job_trigger_with_completion_wait.py
1from prefect import flow
2from prefect_dbt.cloud import DbtCloudCredentials, DbtCloudJob
3
4@flow
5def run_dbt_cloud_job():
6    # Pre-requisite: Create a dbt Cloud Credentials block in the Prefect UI
7    dbt_cloud_credentials = DbtCloudCredentials.load("my-dbt-cloud-creds")
8    
9    # Run a specific job by ID
10    job_run = DbtCloudJob(
11        credentials=dbt_cloud_credentials,
12        job_id=12345,
13        wait_for_job_run_completion=True
14    ).trigger()
15    
16    return job_run
17
18if __name__ == "__main__":
19    run_dbt_cloud_job()