Airflow-Planung

Einführung in Apache Airflow mit Python

Mike Metzger

Data Engineer

DAG Runs

  • Eine konkrete Ausführung eines Workflows zu einem Zeitpunkt
  • Manuell oder per schedule_interval startbar
  • Behält Zustand je Workflow und Task
    • running
    • failed
    • success
1 https://airflow.apache.org/docs/stable/scheduler.html
Einführung in Apache Airflow mit Python

DAG Runs-Ansicht

DAG Runs

Einführung in Apache Airflow mit Python

DAG-Run-Status

DAG-Run-Status

Einführung in Apache Airflow mit Python

Schedule-Details

Beim Planen eines DAG sind wichtige Attribute:

  • start_date – Datum/Uhrzeit des ersten Laufs
  • end_date – Optional: Ende für neue Instanzen
  • max_tries – Optional: Anzahl Versuche
  • schedule_interval – Ausführungsfrequenz
Einführung in Apache Airflow mit Python

Schedule-Intervall

schedule_interval steht für:

  • Wie oft der DAG geplant wird
  • Zwischen start_date und end_date
  • Per cron-Syntax oder vordefinierten Presets
Einführung in Apache Airflow mit Python

cron-Syntax

Cron-Syntax

  • Stammt aus dem Unix-Cron-Format
  • Besteht aus 5 Feldern, getrennt durch Leerzeichen
  • Ein Stern * bedeutet jeden Intervall (z. B. jede Minute, jeden Tag)
  • Felder können kommagetrennte Listen enthalten
Einführung in Apache Airflow mit Python

cron-Beispiele

0 12 * * *              # Täglich um 12 Uhr
* * 25 2 *              # Jede Minute am 25. Februar
0,15,30,45 * * * *      # Alle 15 Minuten
Einführung in Apache Airflow mit Python

Airflow-Scheduler-Presets

Presets:

  • @hourly
  • @daily
  • @weekly
  • @monthly
  • @yearly

cron-Äquivalent:

  • 0 * * * *
  • 0 0 * * *
  • 0 0 * * 0
  • 0 0 1 * *
  • 0 0 1 1 *
1 https://airflow.apache.org/docs/stable/scheduler.html
Einführung in Apache Airflow mit Python

Spezielle Presets

Airflow hat zwei spezielle schedule_interval-Presets:

  • None – nie planen, für manuell ausgelöste DAGs
  • @once – nur einmal planen
Einführung in Apache Airflow mit Python

Probleme mit schedule_interval

Beim Planen eines DAG macht Airflow Folgendes:

  • Nutzt start_date als frühesten Zeitpunkt
  • Plant bei start_date + schedule_interval
'start_date': datetime(2020, 2, 25),
'schedule_interval': @daily

Das heißt, der früheste Lauf ist am 26. Februar 2020

Einführung in Apache Airflow mit Python

Lass uns üben!

Einführung in Apache Airflow mit Python

Preparing Video For Download...