Airflow Task Dependency Sensor¶
The AirflowTaskDependencySensor is a native brickflow sensor that polls a
remote Airflow cluster's REST API to wait for a specific DAG task to reach
an allowed state. It has no dependency on apache-airflow on the
Databricks side -- it only needs requests.
Prior versions shipped a TaskDependencySensor and an
AirflowProxyOktaClusterAuth class that both subclassed Airflow. Those
classes are still importable from brickflow_plugins but now raise
RuntimeError on instantiation. Migrate to
AirflowTaskDependencySensor and the plain AirflowCluster dataclass:
from datetime import timedelta
from brickflow_plugins import AirflowCluster, AirflowTaskDependencySensor
sensor = AirflowTaskDependencySensor(
dag_id="my_upstream_dag",
task_id="final_task",
cluster=AirflowCluster(
url="https://airflow.example.com",
version="2.0.2",
token=my_bearer_token, # compute this from Okta/etc. yourself
),
allowed_states=["success"],
execution_delta=timedelta(hours=0),
timeout_seconds=3600,
poke_interval=60,
)
sensor.execute()
Supported Airflow versions¶
The sensor auto-routes to the correct REST API dialect based on the
AirflowCluster.version string:
version starts with |
Endpoint prefix | Notes |
|---|---|---|
"1." |
/api/experimental |
Airflow 1.x |
| any other value (default) | /api/v1 |
Airflow 2.x |
"3." |
/api/v2 |
Airflow 3.x (FastAPI). Uses logical_date_gte in place of execution_date_gte, and drops asset-triggered runs that have logical_date=null. |
Airflow 3.x example¶
from datetime import timedelta
from brickflow_plugins import AirflowCluster, AirflowTaskDependencySensor
sensor = AirflowTaskDependencySensor(
dag_id="my_upstream_dag",
task_id="final_task",
cluster=AirflowCluster(
url="https://airflow.example.com",
version="3.0.0",
token=my_jwt, # short-lived JWT from Okta/MAP or POST /auth/token
),
allowed_states=["success"],
execution_delta=timedelta(hours=0),
timeout_seconds=3600,
poke_interval=60,
)
sensor.execute()
Auth is unchanged: bring your own bearer token in cluster.token. The sensor
does not call /auth/token for you.
API Reference¶
Airflow Task Dependency Sensor.
Native brickflow sensor that polls an external Airflow API to check the
status of a specific task in an Airflow DAG. Supports Airflow 1.x
(/api/experimental), 2.x (/api/v1), and 3.x (/api/v2) API
shapes. Requires only requests -- no apache-airflow package
needs to be installed on the Databricks cluster.
Classes¶
brickflow_plugins.sensors.airflow_task_dependency_sensor.AirflowCluster(url: str, version: str, token: str)
¶
Represents an Airflow cluster the sensor polls.
Parameters¶
url : str
Base URL of the Airflow API (e.g. https://airflow.example.com).
version : str
Airflow major version string, e.g. "1.10", "2.0.2", or
"3.0.0". Used to select between the /api/experimental
(Airflow 1.x), /api/v1 (Airflow 2.x), and /api/v2
(Airflow 3.x) endpoint shapes.
token : str
Bearer token that will be sent in the Authorization header.
For Airflow 3.x, this is typically a short-lived JWT obtained
out-of-band (e.g. via Okta, MAP, or POST /auth/token).
Source code in brickflow_plugins/sensors/airflow_task_dependency_sensor.py
brickflow_plugins.sensors.airflow_task_dependency_sensor.AirflowTaskDependencySensor(dag_id: str, task_id: str, cluster: AirflowCluster, allowed_states: Optional[List[str]] = None, execution_delta: timedelta = timedelta(days=0), latest: bool = False, timeout_seconds: int = 3600, poke_interval: int = 60)
¶
Bases: Sensor
Sensor that polls an external Airflow cluster's API to wait until a given task in a given DAG reaches an allowed state.
The API dialect used is selected from cluster.version:
"1.x"->/api/experimental"2.x"(default) ->/api/v1"3.x"->/api/v2(FastAPI,logical_datefilters)
Example¶
::
sensor = AirflowTaskDependencySensor(
dag_id="my_upstream_dag",
task_id="final_task",
cluster=AirflowCluster(
url="https://airflow.example.com",
version="2.0.2", # use "3.0.0" for Airflow 3.x (/api/v2)
token=my_token,
),
execution_delta=timedelta(hours=0),
timeout_seconds=3600,
poke_interval=60,
)
sensor.execute()
Source code in brickflow_plugins/sensors/airflow_task_dependency_sensor.py
Attributes¶
allowed_states = allowed_states if allowed_states else ['success']
instance-attribute
¶
cluster = cluster
instance-attribute
¶
dag_id = dag_id
instance-attribute
¶
execution_delta = execution_delta
instance-attribute
¶
latest = latest
instance-attribute
¶
poke_interval = poke_interval
instance-attribute
¶
task_id = task_id
instance-attribute
¶
timeout = timeout_seconds
instance-attribute
¶
Functions¶
execute() -> None
¶
Poll the Airflow API until the task reaches an allowed state or the timeout is exceeded.
Raises¶
TimeoutError
If self.timeout seconds elapse before the task reaches an
allowed state.
Source code in brickflow_plugins/sensors/airflow_task_dependency_sensor.py
get_execution_stats(execution_date: datetime, max_end_date: Optional[datetime] = None) -> str
¶
Return the state of self.task_id for the most recent
self.dag_id DAG run in the given window.
Returns "none" when no matching DAG run is found.
Source code in brickflow_plugins/sensors/airflow_task_dependency_sensor.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
poke() -> str
¶
Poke the Airflow API once and return the task state.
Source code in brickflow_plugins/sensors/airflow_task_dependency_sensor.py
Autosys Sensor¶
Autosys Sensor.
Native brickflow sensor that polls the Autosys REST API to wait for a job
to reach a successful state. Requires only requests -- no
apache-airflow package needs to be installed on the Databricks cluster.
Classes¶
brickflow_plugins.sensors.autosys_sensor.AutosysSensor(url: str, job_name: str, poke_interval: int, time_delta: Union[timedelta, dict] = timedelta(days=0))
¶
Bases: Sensor
Sensor that polls an Autosys REST endpoint for the given job_name
and waits until it reports a successful status recent enough to satisfy
time_delta.
Example¶
::
sensor = AutosysSensor(
url="https://autosys.example.com/api/jobs",
job_name="my_upstream_job",
poke_interval=60,
time_delta=timedelta(hours=1),
)
sensor.poke()
Source code in brickflow_plugins/sensors/autosys_sensor.py
Attributes¶
job_name = job_name
instance-attribute
¶
poke_interval = poke_interval
instance-attribute
¶
time_delta = time_delta
instance-attribute
¶
url = str(url).rstrip('/')
instance-attribute
¶
Functions¶
poke()
¶
Poke the Autosys API once. Recurses (via time.sleep + self-call) until success.