Databricks DE Β· Topic 7.2
Make a job dynamic: branch with if/else (condition_task), loop with for-each, pass data with task values, and run tasks conditionally with run_if rules. This deep dive pairs each with the bundle YAML.
condition_task) branches on a condition, For-each (for_each_task) loops a task over a list, task values pass small data between tasks, and run_if controls when a task runs based on upstream outcomes.βΈ condition: row_count >= 100 β publish, else β quarantine
# upstream task ("ingest"): publish a value dbutils.jobs.taskValues.set(key="row_count", value=1234) # downstream task: read it n = dbutils.jobs.taskValues.get(taskKey="ingest", key="row_count", default=0)
Reference a value in a condition/param with {{tasks.ingest.values.row_count}}. Values are small (counts/flags) β for big data, write a table and pass a pointer.
tasks: - task_key: gate condition_task: op: GREATER_THAN # EQUAL_TO, LESS_THAN, GREATER_THAN_OR_EQUAL, ... left: "{{tasks.ingest.values.row_count}}" right: "100" - task_key: publish_gold # runs only when gate == true depends_on: [{ task_key: gate, outcome: "true" }] notebook_task: { notebook_path: ../src/publish.py } - task_key: quarantine # runs only when gate == false depends_on: [{ task_key: gate, outcome: "false" }] notebook_task: { notebook_path: ../src/quarantine.py }
tasks: - task_key: ingest_all for_each_task: inputs: '["sales","orders","users"]' # or a task value / job param concurrency: 4 # bound the parallelism task: task_key: ingest_one notebook_task: notebook_path: ../src/ingest_table.py base_parameters: { table: "{{input}}" } # current item
op + left + right); downstream tasks attach to the true/false outcome.inputs, passing {{input}} each iteration; concurrency bounds parallelism.dbutils.jobs.taskValues.set/get pass small data between tasks without external storage.ALL_DONE / AT_LEAST_ONE_FAILED for cleanup & alerts.run_if value | Runs when⦠| Use for |
|---|---|---|
ALL_SUCCESS (default) | every dependency succeeded | normal flow |
AT_LEAST_ONE_SUCCESS | β₯1 dependency succeeded | best-effort merge |
NONE_FAILED | none failed (skips allowed) | tolerant continue |
ALL_DONE | all finished (success or fail) | cleanup |
AT_LEAST_ONE_FAILED | β₯1 dependency failed | alerting |
ALL_FAILED | all failed | fallback path |
- task_key: alert_on_failure depends_on: [{ task_key: ingest_all }, { task_key: publish_gold }] run_if: AT_LEAST_ONE_FAILED # fire only when something upstream failed notebook_task: { notebook_path: ../src/alert.py }
concurrency + limits), batch huge lists; run_if defaults to ALL_SUCCESS.run_if defaults to ALL_SUCCESS β cleanup/alert won't run after a failure unless set to AT_LEAST_ONE_FAILED / ALL_DONE.if in code when you need task-level branching (so DAG/monitoring reflects it) β use condition_task.concurrency.