Sub topic 1
What a job, a task, and a run are
Prerequisites
This chapter assumes you have used Databricks notebooks and can read basic Python or SQL. You should also have a general idea of what clusters and compute are in Databricks. Familiarity with cron-style schedules helps for later chapters, but you don't need it here.
The three core objects
A Databricks job is a saved definition of work that you want to run, with its settings. A job holds one or more tasks, plus the settings that apply to the whole job: schedule, parameters, concurrency limit, notifications, and permissions.
A task is one unit of work inside a job. A task might run a notebook, a Python script, a SQL query, or a pipeline. Each task has a task_key, which is a name that is unique within the job. Other tasks use this key to refer to it.
A run is one execution of a job. Each time a schedule fires, a trigger fires, or you click Run now, Databricks creates a new run. A run contains one task run for every task in the job. Each run has its own run ID, status, start time, and output.
The job is the definition, and the run is what happened when that definition was executed. Editing a job does not change runs that already finished.
A minimal job definition
The Jobs API describes a job as JSON. This example defines a job with a single task. It uses the same fields you see later in larger examples.
{
"name": "hello-job",
"max_concurrent_runs": 1,
"job_clusters": [
{
"job_cluster_key": "etl_cluster",
"new_cluster": {
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"num_workers": 2
}
}
],
"tasks": [
{
"task_key": "ingest",
"job_cluster_key": "etl_cluster",
"notebook_task": {"notebook_path": "/Workspace/Shared/ingest"}
}
]
}The name and max_concurrent_runs fields belong to the job. The task_key and notebook_task fields belong to the task. The node type i3.xlarge is specific to AWS, so use a node type that exists on your cloud.
Run states
A run moves through states such as pending, running, and terminated. A terminated run ends with a result such as success, failed, or canceled. Each task run has its own state, so a run can finish with some tasks succeeded and one failed. Later chapters show how to use this when you repair a run.
Key points
- A job is the definition, a task is a step in it, and a run is one execution.
- Settings such as schedule and concurrency belong to the job. Settings such as notebook path and retries belong to the task.
- Every run keeps its own status and output, and so does every task run inside it.
Exercise
You change the notebook path of the task "ingest" in a job after a run has finished. Does the finished run change? Which object holds the new path?
Show answer
The finished run does not change. The new path is stored in the job definition (in the task "ingest"), and only runs started after the edit use it.