Community研究&データ分析github.com

Unknown-333/authoring-airflow-dags

TaskFlow APIを使ってプロダクション品質のApache Airflow DAGを作成するスキル — べき等なタスク、正しいスケジューリングとキャッチアップ、リトライ/SLA、接続情報/変数、トップレベルコードの回避。Airflow DAGの作成やレビュー、パイプラインのスケジューリング、タスク依存関係の配線、リトライ/バックフィルの設定、非べき等タスクの修正時に使用します。

authoring-airflow-dags とは?

このスキルは、Apache Airflow DAGをプロダクション品質で作成・リファクタリングするための包括的なガイドを提供します。主なトピックとして、データインターバルに基づくべき等タスクの実装、TaskFlow APIを使用したタスク間のデータ受け渡し(XCom)、スケジュールとキャッチアップの意図的な設定、リトライとSLAの構成、そしてシークレットや設定のためのAirflow接続/変数の利用が含まれます。トップレベルでのデータベース呼び出しや重いインポートがスケジューラに与える悪影響を回避し、適切な依存関係の配線方法を示します。また、よくある落とし穴として、トップレベルでのAPI/DB呼び出し、べき等性を破るdatetime.now()の使用、意図しないcatchup=True、XCom経由の大きなペイロード渡し、動的なstart_date、モンスタータスクの作成などを挙げ、それぞれの対策を説明します。このスキルは、Claude CodeやCursorなどのAIエージェントプラットフォームで、新しいDAGの作成、既存DAGのレビュー、パイプラインのトラブルシューティング時に適用できます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Unknown-333/awesome-data-engineering-skills/tree/main/skills/authoring-airflow-dags

Installed? Explore more 研究&データ分析 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Airflow DAGの作成

使用するタイミング

  • AirflowのDAGやタスクを作成またはリファクタリングするとき。
  • スケジュール、キャッチアップ/バックフィル、リトライ、SLAを設定するとき。
  • タスク間でデータを受け渡す(XCom)とき、または接続情報/変数を使用するとき。
  • 実行中のDAGが壊れた場合の診断には使用しない(debugging-airflow-pipelinesを使用)。

ワークフロー

- [ ] 各タスクをべき等にし、データインターバルでパラメータ化する
- [ ] 負荷の高い/インポートが多いコードはタスク内部に置き、モジュールのトップレベルに置かない
- [ ] スケジュール + catchupを意図的に設定する
- [ ] リトライ、retry_delay、SLAを設定する
- [ ] TaskFlowの戻り値または >> 演算子で依存関係を配線する
  1. べき等タスク — 2026-01-15 インターバルのタスクは、1回実行しても再実行しても同じ結果を生成しなければなりません。datetime.now() ではなく、データインターバルを使用します。
  2. 重いトップレベルコードを置かない — スケジューラはすべてのDAGファイルを頻繁にパースします。モジュールレベルでのデータベース呼び出し、API呼び出し、大きなインポートはスケジューリングを遅くし、パースを壊す可能性があります。それらはタスク内部に置いてください。
  3. スケジュール + catchupを意図的に設定する — catchup=True は start_date からのすべての見逃したインターバルをバックフィルします。それが望みでなければ、デフォルトは False にします。
  4. リトライとSLA — 一時的な障害は普通です。retries と retry_delay を設定し、遅延に対してSLA/アラートを使用します。

パターン

TaskFlow DAG、べき等でクリーンに配線:

from airflow.decorators import dag, task
import pendulum

@dag(
    schedule="@daily",
    start_date=pendulum.datetime(2026, 1, 1, tz="UTC"),
    catchup=False,
    default_args={"retries": 3, "retry_delay": pendulum.duration(minutes=5)},
    tags=["orders"],
)
def orders_pipeline():

    @task
    def extract(data_interval_start=None):
        # インターバルを使用し、now() は使わないこと。再実行が決定論的になる。
        return fetch_orders(day=data_interval_start.date())

    @task
    def load(rows):
        # パーティションを削除して挿入 -> リトライ時にべき等。
        overwrite_partition("fct_orders", rows)

    load(extract())

orders_pipeline()

小さなデータはXCom(戻り値)経由で渡し、大きなデータはストレージ経由で渡す — S3/GCS/ウェアハウスに書き込み、パス/キーを渡します。メガバイト単位のデータをXComで渡さないでください。

シークレットや設定には接続情報/変数を使用する(BaseHook.get_connection、Variable.get)。ハードコードされた認証情報は決して使わないでください。

よくある落とし穴

  • トップレベルのAPI/DB呼び出しや重いインポート — スケジューラを遅くし、デプロイ全体でDAGのパースに失敗する可能性があります。
  • タスク内での datetime.now() の使用 — べき等性とバックフィルを壊します。data_interval_start/_end を使用してください。
  • 意図しない catchup=True — 最初のデプロイ時に履歴実行でクラスタをあふれさせます。
  • XCom経由の大きなペイロード — メタデータデータベースを肥大化させます。参照を渡してください。
  • 動的な start_date(例:days_ago) — スケジュールを非決定論的にします。固定のタイムスタンプを使用してください。
  • 一つの巨大タスク — 抽出/変換/ロードを分割して、リトライを細かくします。

参考資料

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

Unknown-333/building-dagster-assets

Build Dagster pipelines using software-defined assets — asset dependencies, partitions, resources and IO managers, asset checks, and schedules/sensors. Use when creating Dagster assets or jobs, modeling data as assets, adding partitions or backfills, wiring resources/IO managers, or migrating from task-based orchestration to assets.

Unknown-333/building-dbt-models

Build well-structured dbt models — staging/intermediate/marts layers, ref() and source(), materializations, and incremental models with the right strategy. Use when creating or refactoring dbt models, choosing table vs view vs incremental, structuring a dbt project, or writing incremental logic.

Unknown-333/building-feature-pipelines

Build ML feature pipelines and feature stores — point-in-time-correct joins to avoid label leakage, offline/online parity, feature freshness and backfills, and materialization with tools like Feast. Use when engineering features for ML, preventing train/serve skew or data leakage, building a feature store, or backfilling historical features for training.

Unknown-333/building-iceberg-tables

Design and operate Apache Iceberg tables — partitioning and hidden partitioning, partition/schema evolution, snapshots and time travel, compaction and small-file cleanup, and MERGE/upsert for lakehouse tables on Spark, Flink, Trino, or Snowflake. Use when creating or maintaining Iceberg tables, choosing partitioning, evolving schema/partitions, or fixing small-file and metadata bloat.

Unknown-333/building-ingestion-pipelines

Build batch and incremental data ingestion (extract-load) pipelines — full vs incremental extraction, change data capture (CDC), watermarks and high-water marks, API pagination and rate limits, and choosing managed EL tools (Fivetran, Airbyte) vs custom code. Use when ingesting data from databases, APIs, files, or SaaS into a warehouse/lake, or designing incremental extraction and CDC.

Unknown-333/building-kafka-consumers

Build reliable Apache Kafka consumers and producers — consumer groups and partition assignment, offset commit strategy, at-least-once vs exactly-once, idempotent/transactional producers, rebalancing, and dead-letter handling. Use when writing Kafka consumers/producers, configuring offset commits or consumer groups, tuning throughput, or handling rebalances and poison messages.

Unknown-333/debugging-data-pipelines

Systematically root-cause data pipeline failures and data incidents — job errors, wrong or missing data, duplicates, and freshness misses — by tracing lineage upstream, isolating the failing stage, reconciling against source, and planning a safe fix and backfill. Use when a pipeline fails, numbers look wrong, data is missing or duplicated, a dashboard is stale, or a stakeholder reports a data discrepancy.

Unknown-333/designing-backfills-and-replays

Plan and run safe data backfills and replays — idempotent reprocessing of historical windows, partition-by-partition execution, isolating backfill compute from production, verifying results, and avoiding double-counting or changed history. Use when backfilling a new or fixed model, reprocessing after a bug, replaying events, or loading history for a new pipeline without corrupting existing data.

Unknown-333/designing-data-contracts

Define and enforce data contracts between producers and consumers — explicit schema, semantics, ownership, SLAs, and versioning — to prevent silent upstream changes from breaking downstream pipelines. Use when a producer schema change could break consumers, defining an interface between teams/services and the warehouse, or adding schema enforcement at ingestion.

関連スキル