Airflow-planning

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_interval te starten
  • Behoudt status voor elke workflow en taak
    • running
    • failed
    • success
1 https://airflow.apache.org/docs/stable/scheduler.html
Introductie tot Apache Airflow in Python

DAG-runs-weergave

DAG-runs

Introductie tot Apache Airflow in Python

DAG-runstatus

DAG-runstatus

Introductie tot Apache Airflow in Python

Planningsdetails

Bij het plannen van een DAG zijn dit belangrijke attributen:

  • start_date - Datum/tijd om de eerste run in te plannen
  • end_date - Optioneel: wanneer stoppen met nieuwe runs
  • max_tries - Optioneel: maximaal aantal pogingen
  • schedule_interval - Hoe vaak uitvoeren
Introductie tot Apache Airflow in Python

Schedule-interval

schedule_interval betekent:

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

cron-syntaxis

Cron-syntaxis

  • Afkomstig uit de Unix-cronindeling
  • Bestaat uit 5 velden, gescheiden door een spatie
  • Een asterisk * betekent elke interval (bijv. elke minuut, elke dag)
  • Velden kunnen kommagescheiden lijsten bevatten
Introductie tot Apache Airflow in Python

cron-voorbeelden

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 twee speciale schedule_interval-presets:

  • None - Nooit inplannen; voor handmatig getriggerde DAG's
  • @once - Slechts één keer plannen
Introductie tot Apache Airflow in Python

Problemen met schedule_interval

Bij het plannen van een DAG doet Airflow het volgende:

  • Gebruikt start_date als vroegste moment
  • Plant de taak op start_date + schedule_interval
'start_date': datetime(2020, 2, 25),
'schedule_interval': @daily

Dit betekent dat de vroegste starttijd 26 februari 2020 is

Introductie tot Apache Airflow in Python

Laten we oefenen!

Introductie tot Apache Airflow in Python

Preparing Video For Download...