Lesson 3 · Foundations
Operators, sensors & the TaskFlow API
The three flavours of task — and which this repo actually uses.
Your win: name the three ways to define a task and pick the right one — a certification staple, grounded in the operators this repo runs.
A task comes in three flavours
Operator
A pre-built, reusable task template you configure with arguments —
PythonOperator, BashOperator,
SparkKubernetesOperator, KubernetesPodOperator. All derive
from BaseOperator.
Sensor
A special operator that waits for a condition — a file to arrive, a partition to exist, a time to pass — then succeeds.
TaskFlow @task
Your plain Python function turned into a task by the @task decorator;
Airflow wires XCom and dependencies for you. The modern style.
All three produce tasks in the DAG (Lesson 2) — they're just different ways to define one.1
What this repo uses
SparkKubernetesOperator (60 — submits a Spark job),
KubernetesPodOperator (10 — runs a container), PythonOperator
(8 — e.g. read Variables → push XCom), BashOperator (3). ⚠️ There are
no sensors anywhere in airflow/ (the airflow-job
skill's SparkKubernetesSensor example isn't actually used here) — and little
TaskFlow, since the repo generates classic-operator DAGs. But the certification
expects all three, so learn the concept even where the repo skips it.
When to use which
@task
for custom Python logic where you want clean code and automatic XCom.
Airflow — Operators + the TaskFlow API
The core-concepts pages for operators (and sensors as a subclass) and the TaskFlow
@task style.
Check yourself (from memory)
Q1. An operator is best described as a…
BaseOperator.
Q2. A sensor is an operator that…
Q3. The TaskFlow @task decorator turns…
@task — a plain Python
function as a task, with XCom + dependencies wired automatically (modern style). Our repo
is operator-heavy (SparkKubernetesOperator dominates), uses NO sensors, and little
TaskFlow — but the certification expects all three.@task,
side by side? Ask me.
1. Airflow — Tasks (operators, sensors, TaskFlow).