Sub topic 2
Event-Based and Periodic Triggers
Assume you can use Databricks notebooks and understand basic clusters, Python, and cron-style schedules. A workflow trigger starts a job run. A periodic trigger starts it at times defined by a schedule. An event-based trigger starts it when an external event occurs.
Choosing a Trigger
Use a periodic trigger for predictable batches, such as a daily sales load. Use a file-arrival trigger when new data should start processing.
{
"schedule": {
"quartz_cron_expression": "0 0 6 * * ?",
"timezone_id": "UTC",
"pause_status": "UNPAUSED"
},
"trigger": {
"file_arrival": {
"url": "s3://company-data/orders/"
}
}
}A job normally uses either a schedule or a file-arrival trigger. Check the trigger settings for your Databricks workspace and cloud storage provider before deploying.
Parameters and Task Values
Job parameters provide inputs such as a date or source path. Dynamic references let tasks read those inputs.
Task values pass results from one task to another. The upstream task publishes a named value. The downstream task reads it by task key.
# In the ingest task
row_count = spark.table("sales.raw_orders").count()
dbutils.jobs.taskValues.set(key="row_count", value=row_count)
# In the transform task
row_count = dbutils.jobs.taskValues.get(
taskKey="ingest",
key="row_count",
default=0,
debugValue=0
)
print(f"Rows received: {row_count}")The debugValue makes interactive notebook testing possible. It does not replace the value during a job run.
Controlling Execution
run_if rules determine whether a task runs after its dependencies finish. For example, a cleanup task can use ALL_DONE so it runs after success or failure. Use ALL_SUCCESS when downstream work must stop after an upstream failure.
An If/else condition task evaluates a value and produces a true or false outcome. Depend on a specific outcome to create a branch, such as processing only when row_count is greater than zero.
Retries and Timeouts
Retries handle temporary failures, such as a brief network outage. Set a task timeout so a stuck task does not consume compute indefinitely. Avoid retrying non-idempotent tasks unless repeating them is safe.
> callout warning > Retries do not fix invalid input or broken code. Make writes idempotent so a retry cannot duplicate results.
Exercise
Which trigger and dependency rule fit a daily pipeline that should process new files and stop transformation after ingestion fails?
Show answer
Use a file-arrival trigger and an ALL_SUCCESS dependency for the transformation task.