Workflow Dependency Sensor¶
The WorkflowDependencySensor and WorkflowTaskDependencySensor allow you to create cross-workflow dependencies in Databricks. Use these sensors to wait for an upstream workflow (or a specific task within it) to complete before proceeding with your own workflow's tasks.
WorkflowDependencySensor¶
Monitors an entire Databricks workflow and waits for a successful run within a configurable time window. Suitable when you need to depend on the overall completion of an upstream job.
WorkflowTaskDependencySensor¶
Monitors a specific task within a Databricks workflow. This provides finer-grained control when you only need a particular task to complete rather than the entire workflow.
Handling skipped tasks¶
By default, the sensor only considers tasks with a SUCCESS result state as completed. Some workflows use conditional logic that causes certain tasks to be skipped (reported as EXCLUDED by Databricks). If a skipped task should be treated as a valid completion state, set the allow_skipped parameter to True:
sensor = WorkflowTaskDependencySensor(
dependency_job_name="upstream_job",
dependency_task_name="conditional_task",
delta=timedelta(days=1),
timeout_seconds=300,
allow_skipped=True, # treat EXCLUDED tasks as successful
)
sensor.execute()
When allow_skipped=False (the default), only SUCCESS is accepted. When allow_skipped=True, both SUCCESS and EXCLUDED states are accepted.
API Reference¶
Classes¶
brickflow_plugins.sensors.workflow_dependency_sensor.WorkflowDependencySensor(databricks_host: str, databricks_token: Union[str, SecretStr], delta: timedelta, timeout_seconds: int, dependency_job_id: int = None, dependency_job_name: str = None, poke_interval_seconds: int = 60)
¶
This is used to have dependencies on the databricks workflow
Example Usage in your brickflow task
service_principle_pat = ctx.dbutils.secrets.get("brickflow-demo-tobedeleted", "service_principle_id") WorkflowDependencySensor( databricks_host=https://your_workspace_url.cloud.databricks.com, databricks_token=service_principle_pat, dependency_job_id=job_id, poke_interval=20, timeout=60, delta=timedelta(days=1) ) In above snippet Databricks secrets is used as a secure service to store the databricks token. If you get your token from another secret management service, like AWS Secrets Manager, GCP Secret Manager or Azure Key Vault, just pass it in the databricks_token argument.
Source code in brickflow_plugins/sensors/workflow_dependency_sensor.py
Attributes¶
databricks_host = databricks_host
instance-attribute
¶
databricks_token = databricks_token if isinstance(databricks_token, SecretStr) else SecretStr(databricks_token)
instance-attribute
¶
delta = delta
instance-attribute
¶
dependency_job_id = dependency_job_id
instance-attribute
¶
dependency_job_name = dependency_job_name
instance-attribute
¶
log = logging
instance-attribute
¶
poke_interval = poke_interval_seconds
instance-attribute
¶
start_time = time.time()
instance-attribute
¶
timeout = timeout_seconds
instance-attribute
¶
Functions¶
execute()
¶
Source code in brickflow_plugins/sensors/workflow_dependency_sensor.py
get_execution_start_time_unix_milliseconds() -> int
¶
Source code in brickflow_plugins/sensors/workflow_dependency_sensor.py
get_http_session()
cached
¶
Source code in brickflow_plugins/sensors/workflow_dependency_sensor.py
get_retry_class(max_retries)
¶
Source code in brickflow_plugins/sensors/workflow_dependency_sensor.py
brickflow_plugins.sensors.workflow_dependency_sensor.WorkflowTaskDependencySensor(dependency_job_name: str, dependency_task_name: str, delta: timedelta, timeout_seconds: int, databricks_host: str = None, databricks_token: Union[str, SecretStr] = None, poke_interval_seconds: int = 60, allow_skipped: bool = False)
¶
Bases: WorkflowDependencySensor
This is used to have dependencies on the specific task within a databricks workflow
Example Usage in your brickflow task
service_principle_pat = ctx.dbutils.secrets.get("scope", "service_principle_id") WorkflowTaskDependencySensor( databricks_host=https://your_workspace_url.cloud.databricks.com, databricks_token=service_principle_pat, dependency_job_name="my_job", dependency_task_name="foo", poke_interval_seconds=20, timeout_seconds=60, delta=timedelta(days=1), allow_skipped=True # Optional: treat skipped (EXCLUDED) tasks as successful ) In the above snippet Databricks secrets are used as a secure service to store the databricks token. If you get your token from another secret management service, like AWS Secrets Manager, GCP Secret Manager or Azure Key Vault, just pass it in the databricks_token argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dependency_job_name
|
str
|
Name of the job to monitor |
required |
dependency_task_name
|
str
|
Name of the task within the job to monitor |
required |
delta
|
timedelta
|
Time delta to look back for runs |
required |
timeout_seconds
|
int
|
Maximum time to wait before timing out |
required |
databricks_host
|
str
|
Databricks workspace URL |
None
|
databricks_token
|
Union[str, SecretStr]
|
Databricks authentication token |
None
|
poke_interval_seconds
|
int
|
Interval between checks (default: 60) |
60
|
allow_skipped
|
bool
|
If True, treat skipped (EXCLUDED) tasks as successful (default: False) |
False
|