Synchronous dag execution refers to the ability in Airflow 3.1+ to trigger a dag run via an API call and wait for it to complete before returning XCom values pushed by one or more tasks in the dag run. This is useful both for single DAG runs and for cases where the same DAG may be triggered multiple times in parallel.
Synchronous dag execution was added as an experimental feature in Airflow 3.1.
Synchronous dag execution is a way to use Airflow as the backend for services processing user requests coming from a frontend application like a website, mobile app, or slack bot. Common use cases include:
The endpoint to wait for a dag run to complete is:
It includes the following path parameters:
dag_id: (Mandatory) The id of the DAG to wait for.dag_run_id: (Mandatory) The id of the DAG run to wait for.The query parameters are:
interval: (Mandatory) Seconds to wait between dag run state checks.result: (Optional) Array of strings or null. A list of task ids from which to pull the XCom value pushed under the return_value key.Calling this endpoint on any running dag will start a waiting process until the dag run completes. If any XCom are requested in the result parameter, they are returned in the response upon dag run completion.
The following script creates a dag run for the my_dag dag and waits for it to complete. It includes XComs pushed under the return_value key of the my_task task in the response.
Running the script above returns an output similar to the following: