Sub topic 16
Composing Workflows with Run Job Tasks
This chapter assumes you can create a multi-task job, define task dependencies, and set job parameters. A Run Job task lets one job start another job as a single step. You use it to split a large workflow into smaller jobs that you can build, test, and reuse separately.
Why compose jobs
A job with dozens of tasks is hard to read and hard to repair. If several pipelines share the same steps, such as a data quality check, copying those tasks into each job leads to drift. A Run Job task solves both problems. The parent job treats the child job as one node in its graph.
Common uses:
- Reuse one child job from several parent jobs.
- Run a nightly parent that calls an ingestion job, a transformation job, and a reporting job in order.
- Give each team ownership of its own job while a parent job coordinates the order.
How a Run Job task behaves
The parent starts the child job and waits for it to finish. The Run Job task succeeds when the child run succeeds and fails when the child run fails. Because it is a normal task, it supports depends_on, run_if, retries, and notifications.
Defining a Run Job task
The task names the child job by its ID and can pass job parameters to it. The JSON below uses a placeholder job ID. Replace it with the ID of your own job.
{
"name": "nightly-orchestrator",
"tasks": [
{
"task_key": "run_ingest",
"run_job_task": {
"job_id": 111111111111,
"job_parameters": {
"run_date": "{{job.start_time.iso_date}}"
}
}
},
{
"task_key": "run_transform",
"depends_on": [{"task_key": "run_ingest"}],
"run_job_task": {
"job_id": 222222222222
}
}
]
}The parent sends run_date as a job parameter. The child job must define a job parameter with the same name, or the value is not used. The {{job.start_time.iso_date}} reference is a dynamic value that Databricks fills in when the parent run starts.
Things to watch
- No compute on the Run Job task. The task only starts the child. The child job uses its own compute settings.
- Permissions. The identity that runs the parent needs permission to run the child job. See the chapter on permissions and the run-as identity.
- Concurrency. The child job has its own maximum concurrent runs setting. If the child is already at its limit, the new run can be skipped or can fail, depending on settings.
- Cycles. A job must not call itself, directly or through another job. Databricks rejects such definitions.
- Repair. If a child fails, you repair the parent run. The child run is started again as part of that repair.
Run Job or one large job?
| Situation | Better choice |
|---|---|
| Tasks always run together and share one cluster | One job with many tasks |
| A group of tasks is reused by several workflows | Child job with a Run Job task |
| Different teams own different stages | Child jobs, one per team |
| You want to share a job cluster across stages | One job, because a child job cannot use the parent's job cluster |
Exercise
A parent job has a Run Job task that calls a child job. The child job fails on its third task. You want to avoid rerunning work that already succeeded. What do you repair, and which compute does the child use?
Show answer
Repair the parent run, which starts the child run again as part of the repair. The child uses its own compute settings, because a Run Job task has no compute of its own and cannot use the parent's job cluster.