DAG’s plannen

Introductie tot Apache Airflow in Python

Mike Metzger

Data Engineer

DAG-runs

  • Een specifieke uitvoering van een workflow op een moment
  • Handmatig of via schedule te starten
  • Bewaart de status per workflow en taak
    • running
    • failed
    • success
1 https://airflow.apache.org/docs/stable/scheduler.html
Introductie tot Apache Airflow in Python

DAG Runs-weergave

Airflow-pagina DAG Runs met recente runs over alle DAG’s

Introductie tot Apache Airflow in Python

DAG Run-status

Airflow-pagina DAG Runs met kolom state per run

Introductie tot Apache Airflow in Python

Details schema

Bij het plannen van een DAG zijn deze attributen belangrijk:

  • start_date - Datum/tijd om de eerste run in te plannen
  • end_date - Optioneel: wanneer geen nieuwe runs meer starten
    • start_date en end_date gebruiken datetime(year, month, day), zoals:
       from pendulum import datetime
       start_date=datetime(2026, 4, 10, tz="UTC")
      
Introductie tot Apache Airflow in Python

Schema

schedule geeft aan:

  • Hoe vaak de DAG wordt ingepland
  • Tussen start_date en end_date
  • Te definiëren via cron-syntaxis, ingebouwde presets of timedeltas
Introductie tot Apache Airflow in Python

cron-syntaxis

Diagram van cron-syntaxis met vijf door spaties gescheiden tijdsvelden

  • Afkomstig van de Unix cron-indeling
  • 5 velden gescheiden door een spatie
  • * betekent elk interval (bv. elke minuut, elke dag)
  • Velden kunnen komma-gescheiden lijsten bevatten
Introductie tot Apache Airflow in Python

cron-voorbeelden

Diagram van cron-syntaxis met vijf door spaties gescheiden tijdsvelden

0 12 * * *              # Dagelijks om 12:00
* * 25 2 *              # Elke minuut op 25 februari
0,15,30,45 * * * *      # Elke 15 minuten
Introductie tot Apache Airflow in Python

Airflow-schedulerpresets

Presets:

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

cron-equivalent:

  • 0 * * * *
  • 0 0 * * *
  • 0 0 * * 0
  • 0 0 1 * *
  • 0 0 1 1 *
1 https://airflow.apache.org/docs/stable/scheduler.html
Introductie tot Apache Airflow in Python

Speciale presets

Airflow heeft drie speciale schedule-presets:

  • None - Nooit inplannen; voor handmatig getriggerde DAG’s
  • @once - Slechts één keer plannen
  • @continuous - Start direct na afloop van de vorige run
Introductie tot Apache Airflow in Python

timedelta

  • Je kunt ook pendulum.duration gebruiken
  • duration(hours=6)
  • duration(minutes=30)
from pendulum import duration

@dag(
  dag_id="example_dag"
  schedule=duration(days=2)
)
Introductie tot Apache Airflow in Python

Schema toepassen

  • Schema gedefinieerd op de DAG
  • Via de parameter schedule:
@dag(
  dag_id="example_dag",
  schedule="0 12 * * *"
)
@dag(
  dag_id="example_dag",
  schedule="@daily"     
)
Introductie tot Apache Airflow in Python

Schema-aandachtspunten

Bij het plannen van een DAG doet Airflow het volgende:

  • Er moet één volledig interval voorbij de startdatum liggen
  • Plant in op start_date + schedule
'start_date': datetime(2026, 2, 25, tz="UTC")
'schedule': @daily

Vroegste starttijd is 26 februari 2026

Introductie tot Apache Airflow in Python

Laten we oefenen!

Introductie tot Apache Airflow in Python

Preparing Video For Download...