airflow.providers.standard.example_dags.example_measurement_correction_operator¶
Tutorial example Dag: measurement correction storyline (PythonOperator).
Classic, PythonOperator based counterpart of
example_measurement_correction_decorator.py. It runs the same
“read, validate, correct, store” pipeline so that learners can compare the
TaskFlow API and the operator-based style on identical business logic.
The Dag has no external dependencies (no connections, no datasets, no hooks), so it parses and runs out of the box and is suitable as a tutorial or as a documentation snippet.
Attributes¶
Functions¶
|
Return the raw measurement value pushed to XCom. |
|
Validate the upstream measurement pulled from XCom. |
|
Apply the calibration factor to a validated measurement. |
|
Persist the corrected measurement. |
Module Contents¶
- airflow.providers.standard.example_dags.example_measurement_correction_operator.DAG_DOC_MD = Multiline-String[source]¶
Show Value
""" ### Measurement correction (PythonOperator) Tutorial Dag showing a minimal "read, validate, correct, store" measurement pipeline implemented with classic ``PythonOperator`` tasks and XCom for inter-task communication. **Storyline** 1. `read_measurement` returns a raw value. 2. `validate_measurement` pulls it from XCom and rejects negative values. 3. `apply_correction` multiplies it by a calibration factor. 4. `store_result` logs the corrected value. **When to use this example** - Comparing the TaskFlow API with the classic operator style on the same storyline (see ``example_measurement_correction_decorator.py``). - As a reference shape for new "tutorial" example Dags following the [example Dag review checklist]( https://github.com/apache/airflow/blob/main/contributing-docs/28_example_dag_review_checklist.rst). """
- airflow.providers.standard.example_dags.example_measurement_correction_operator.read_measurement(**context)[source]¶
Return the raw measurement value pushed to XCom.
The returned value becomes the task’s XCom payload so the downstream tasks can pull it with
ti.xcom_pull.
- airflow.providers.standard.example_dags.example_measurement_correction_operator.validate_measurement(**context)[source]¶
Validate the upstream measurement pulled from XCom.
Raises
ValueErrorwhen the value is negative so the failure is visible as a failed task in the UI instead of silently corrupting downstream data.
- airflow.providers.standard.example_dags.example_measurement_correction_operator.apply_correction(**context)[source]¶
Apply the calibration factor to a validated measurement.
The factor (
1.1) is hard-coded for brevity; a production pipeline would source it from a Variable, a Connection extra, or a config file.
- airflow.providers.standard.example_dags.example_measurement_correction_operator.store_result(**context)[source]¶
Persist the corrected measurement.
The tutorial implementation logs the value via
printso the result is visible in the task logs. A production Dag would write it to a database, an object store, or publish it to a downstream system.