airflow-dag-patterns
使用經過驗證的模式建構生產級 Airflow DAG
當結構和重試不一致時,Airflow DAG 可能會失敗。本技能提供清晰的設計感測器、測試和警報模式,以提高管線的可靠性。
下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「airflow-dag-patterns」。 Give me a safe pattern for a daily ETL DAG with retries, testing, and a failure callback.
預期結果:
- Use default_args with retries, retry_delay, and exponential backoff
- Define a linear start -> extract -> load -> end structure
- Add a task failure callback to report errors
- Create DagBag tests for load errors, task count, and dependencies
正在使用「airflow-dag-patterns」。 How do I create DAGs dynamically from configuration?
預期結果:
- Define a PIPELINE_CONFIGS list with name, schedule, and source fields
- Create a create_dag factory function that takes a config parameter
- Use globals()[f"dag_{name}"] to register each DAG dynamically
- Apply the same pattern for customers, orders, and products pipelines
正在使用「airflow-dag-patterns」。 Show me how to wait for external dependencies before running tasks.
預期結果:
- Use S3KeySensor to wait for files in S3 buckets
- Use ExternalTaskSensor to wait for upstream DAG completion
- Set mode='reschedule' to free workers while waiting
- Combine multiple sensors with dependencies before processing
安全審計
安全Pure documentation skill containing only Airflow patterns and example code. No executable scripts, network calls, filesystem access, or environment variable reads. All code in SKILL.md is illustrative documentation for building data pipelines.
風險因素
⚡ 包含腳本 (1)
⚙️ 外部命令 (20)
品質評分
你能建構什麼
標準化 ETL DAG
為每日和每小時管線建立一致的 DAG 結構、重試和排程。
新增操作防護措施
套用感測器、警報和失敗回調以提高管線可靠性。
測試 DAG 完整性
撰寫單元測試以確保 DAG 能正確載入、沒有迴圈並遵守依賴關係。
試試這些提示
使用 PythonOperator 和基本 default_args 建立具有開始、擷取和結束任務的每日 Airflow DAG。
草擬一個 TaskFlow API DAG,包含擷取、轉換和載入任務,並在它們之間安全地傳遞資料。
展示在處理前等待 S3 資料和上游 DAG 的模式。
為關鍵 DAG 新增失敗回調、重試和在失敗時執行的清理任務。
最佳實務
- 保持任務冪等性,避免在 DAG 檔案中使用大量邏輯
- 使用 TaskFlow API 和感測器重新排程模式以提高效率
- 為 DAG 載入、結構和迴圈新增單元測試
避免
- 對大多數任務使用 depends_on_past
- 硬編碼日期而非使用 Airflow 巨集
- 在 DAG 檔案中儲存可變的全域狀態
常見問題
這是否相容於 Airflow 2.x?
範例的限制是什麼?
它可以與我現有的 DAG 整合嗎?
它會存取或儲存我的資料嗎?
如果我的 DAG 匯入失敗怎麼辦?
與一般的程式碼輔助相比有何不同?
開發者詳情
作者
wshobson授權
MIT
儲存庫
https://github.com/wshobson/agents/tree/main/plugins/data-engineering/skills/airflow-dag-patterns引用
main
檔案結構
📄 SKILL.md