Chuyển đến nội dung
Skillpedia
Triển khai và đám mây (DevOps)41k · #6669

airflow-dag-patterns

Skill này làm gì

Công cụ này giúp bạn xây dựng các quy trình tự động (gọi là DAG) cho Apache Airflow. Nó hướng dẫn các thực hành tốt nhất để sắp xếp tác vụ, bảo đảm chúng chạy đúng và dễ quản lý.

Khi nào nên dùng

  • ✓Khi bạn tạo một quy trình tự động để chuyển hoặc xử lý dữ liệu.
  • ✓Khi bạn cần một nhóm tác vụ chạy theo một thứ tự nhất định.
  • ✓Khi bạn thiết lập các tác vụ cần lặp lại theo lịch.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/wshobson/agents/blob/main/plugins/data-engineering/skills/airflow-dag-patterns/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm thế nào để tạo một quy trình tự tải một file mỗi ngày lúc 6 giờ sáng rồi xử lý file đó?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ cung cấp các mẫu và ví dụ code cho thấy cách định nghĩa tác vụ, các phụ thuộc giữa chúng và những thiết lập quan trọng. Nó tuân theo các nguyên tắc như đảm bảo một tác vụ có thể chạy nhiều lần mà không gây lỗi (idempotent) và mỗi tác vụ có kết quả rõ ràng (atomic).

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

DAG là gì?

DAG là viết tắt của Directed Acyclic Graph (đồ thị có hướng không có chu trình). Hãy hình dung nó như một sơ đồ cho thấy các tác vụ cần làm và thứ tự thực hiện, không tạo vòng lặp (nghĩa là bạn không quay lại điểm xuất phát).

Tại sao các tác vụ phải “idempotent”?

Idempotent nghĩa là chạy một tác vụ nhiều lần liên tiếp cho kết quả giống như chạy một lần. Điều này rất quan trọng để đáng tin cậy, vì nếu một tác vụ lỗi và phải chạy lại, kết quả cuối cùng vẫn không bị thay đổi.

“Operators” và “sensors” là gì?

Operator là các khối xây dựng cơ bản của DAG, đại diện cho một hành động cần thực hiện (như chạy một script Python). Sensor là một loại operator đặc biệt, chờ một điều gì đó xảy ra rồi mới tiếp tục (như chờ một file được gửi đến).

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
41k
Vị trí xếp hạng
#6669
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự