開始使用免費開始

用 XCom 傳遞資料

你正在把一個 ETL 工作流程更新為使用 XCom,以更方便追蹤資訊。因此,你需要更新 Dag 中各個工作的相依性。

你已經定義了 4 個工作,可如下使用:

  • extract() - 回傳 order_data
  • transform(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()
編輯並執行程式碼