用 XCom 傳遞資料
你正在把一個 ETL 工作流程更新為使用 XCom,以更方便追蹤資訊。因此,你需要更新 Dag 中各個工作的相依性。
你已經定義了 4 個工作,可如下使用:
extract()- 回傳order_datatransform(order_data)- 回傳彙整後的資料load(summary_data)- 不回傳 XCom 資訊send_report()- 非 XCom 的工作,用來處理通知
本練習屬於課程
Python 中的 Apache Airflow 入門
練習說明
- 將
transform工作插入extract()與load()之間,完成串接。 - 把結果指派給名為
etl_result的變數。 - 將
send_report設定為在etl_result變數之後執行。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
@dag(start_date=datetime(2026,4,1))
def etl_example():
# Chain extract, transform, and load, assigning the result
____ = load(____(extract()))
# Run send_report after the ETL tasks
etl_result ____ ____()
etl_example()