本文へスキップ
Skillpedia
デプロイとクラウド(DevOps)41k · #6669

airflow-dag-patterns

できること

このツールは、Apache Airflow向けに、自動化されたワークフロー(DAGと呼ばれます)を構築するのに役立ちます。タスクの整理、正しい実行の確保、管理のしやすさに関するベストプラクティスを教えます。

使う場面

  • ✓データを移動または処理する自動化された処理を作成するとき。
  • ✓特定の順序で実行する必要がある一連のタスクが必要なとき。
  • ✓決まった時刻に繰り返し実行されるタスクを設定するとき。

スキルのリンク

https://github.com/wshobson/agents/blob/main/plugins/data-engineering/skills/airflow-dag-patterns/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/wshobson/agents/blob/main/plugins/data-engineering/skills/airflow-dag-patterns/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“毎日午前6時にファイルをダウンロードして、そのあと処理するワークフローはどう作ればよいですか?”

毎週5つの新しいスキル。1分で読めます。

仕組み

このツールは、タスクの定義、依存関係、重要な設定の方法を示すテンプレートやコード例を提供します。タスクを複数回実行しても問題が起きないこと(冪等性)や、各タスクに明確な結果があること(アトミック性)といった原則に従います。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Apache Airflow DAG Patterns

Production-ready patterns for Apache Airflow including DAG design, operators, sensors, testing, and deployment strategies.

When to Use This Skill

  • Creating data pipeline orchestration with Airflow
  • Designing DAG structures and dependencies
  • Implementing custom operators and sensors
  • Testing Airflow DAGs locally
  • Setting up Airflow in production
  • Debugging failed DAG runs

Core Concepts

1. DAG Design Principles

Principle Description
Idempotent Running twice produces same result
Atomic Tasks succeed or fail completely
Incremental Process only new/changed data
Observable Logs, metrics, alerts at every step

2. Task Dependencies

# Linear
task1 >> task2 >> task3

# Fan-out
task1 >> [task2, task3, task4]

# Fan-in
[task1, task2, task3] >> task4

# Complex
task1 >> task2 >> task4
task1 >> task3 >> task4

Quick Start

# dags/example_dag.py
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.operators.empty import EmptyOperator

default_args = {
    'owner': 'data-team',
    'depends_on_past': False,
    'email_on_failure': True,
    'email_on_retry': False,
    'retries': 3,
    'retry_delay': timedelta(minutes=5),
    'retry_exponential_backoff': True,
    'max_retry_delay': timedelta(hours=1),
}

with DAG(
    dag_id='example_etl',
    default_args=default_args,
    description='Example ETL pipeline',
    schedule='0 6 * * *',  # Daily at 6 AM
    start_date=datetime(2024, 1, 1),
    catchup=False,
    tags=['etl', 'example'],
    max_active_runs=1,
) as dag:

    start = EmptyOperator(task_id='start')

    def extract_data(**context):
        execution_date = context['ds']
        # Extract logic here
        return {'records': 1000}

    extract = PythonOperator(
        task_id='extract',
        python_callable=extract_data,
    )

    end = EmptyOperator(task_id='end')

    start >> extract >> end

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices

Do's

  • Use TaskFlow API - Cleaner code, automatic XCom
  • Set timeouts - Prevent zombie tasks
  • Use mode='reschedule' - For sensors, free up workers
  • Test DAGs - Unit tests and integration tests
  • Idempotent tasks - Safe to retry

Don'ts

  • Don't use depends_on_past=True - Creates bottlenecks
  • Don't hardcode dates - Use {{ ds }} macros
  • Don't use global state - Tasks should be stateless
  • Don't skip catchup blindly - Understand implications
  • Don't put heavy logic in DAG file - Import from modules
よくある質問

DAGとは何ですか?

「有向非巡回グラフ(Directed Acyclic Graph)」の略です。実行すべきタスクとその順序を示す地図のようなもので、ループ(つまり、最初に戻ってしまうこと)は作りません。

タスクが「冪等(idempotent)」であることが重要なのはなぜですか?

冪等とは、タスクを連続して何度実行しても、1回だけ実行した場合と同じ結果になることです。タスクが失敗して再実行が必要になっても最終結果が変わらないことが保証されるため、信頼性の面で非常に重要です。

「オペレーター」と「センサー」とは何ですか?

オペレーターはDAGの基本的な部品で、Pythonスクリプトの実行など、行う処理を表します。センサーは特殊なオペレーターの一種で、ファイルが届くなど、何かが起こるまで待ってから次に進みます。

詳細

作者による元の説明

Build production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.

repo: wshobson/agents

人気

GitHubのスター
41k
ランキング
#6669
ライセンス
MIT
更新日
2026/10/15

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル