Planifier des Dags

Introduction à Apache Airflow en Python

Mike Metzger

Data Engineer

Exécutions de Dag

  • Instance spécifique d’un workflow à un instant donné
  • Peut être lancée manuellement ou via schedule
  • Conserve l’état du workflow et de ses tâches
    • running
    • failed
    • success
1 https://airflow.apache.org/docs/stable/scheduler.html
Introduction à Apache Airflow en Python

Vue Dag Runs

Page Airflow Dag Runs listant les exécutions récentes de tous les Dags

Introduction à Apache Airflow en Python

État des Dag Runs

Page Airflow Dag Runs affichant la colonne d’état pour chaque exécution

Introduction à Apache Airflow en Python

Détails du schedule

Pour planifier un Dag, notez :

  • start_date - Date/heure initiale de planification
  • end_date - Optionnelle, date d’arrêt des nouvelles instances
    • start_date et end_date utilisent un objet datetime(year, month, day), par ex. :
       from pendulum import datetime
       start_date=datetime(2026, 4, 10, tz="UTC")
      
Introduction à Apache Airflow en Python

Schedule

schedule indique :

  • La fréquence d’exécution du Dag
  • Entre start_date et end_date
  • Défini via une syntaxe cron, des préréglages, ou des timedeltas.
Introduction à Apache Airflow en Python

Syntaxe cron

Schéma de la syntaxe cron montrant ses cinq champs temporels séparés par des espaces

  • Issu du format cron Unix
  • 5 champs séparés par un espace
  • * signifie à chaque intervalle (p. ex. chaque minute, chaque jour)
  • Valeurs séparées par des virgules possibles dans un champ
Introduction à Apache Airflow en Python

Exemples cron

Schéma de la syntaxe cron montrant ses cinq champs temporels séparés par des espaces

0 12 * * *              # Exécuter chaque jour à midi
* * 25 2 *              # Exécuter chaque minute le 25 février
0,15,30,45 * * * *      # Exécuter toutes les 15 minutes
Introduction à Apache Airflow en Python

Préréglages du planificateur Airflow

Préréglages :

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

Équivalents cron :

  • 0 * * * *
  • 0 0 * * *
  • 0 0 * * 0
  • 0 0 1 * *
  • 0 0 1 1 *
1 https://airflow.apache.org/docs/stable/scheduler.html
Introduction à Apache Airflow en Python

Préréglages spéciaux

Airflow propose trois préréglages schedule spéciaux :

  • None - Jamais planifié, pour des Dags déclenchés manuellement
  • @once - Planifier une seule fois
  • @continuous - Exécuter dès que l’exécution précédente se termine
Introduction à Apache Airflow en Python

timedelta

  • Peut aussi utiliser pendulum.duration
  • duration(hours=6)
  • duration(minutes=30)
from pendulum import duration

@dag(
  dag_id="example_dag"
  schedule=duration(days=2)
)
Introduction à Apache Airflow en Python

Appliquer des plannings

  • Planification définie sur le Dag
  • Via le paramètre schedule :
@dag(
  dag_id="example_dag",
  schedule="0 12 * * *"
)
@dag(
  dag_id="example_dag",
  schedule="@daily"     
)
Introduction à Apache Airflow en Python

Problèmes de schedule

Lors de la planification d’un Dag, Airflow :

  • Attend un intervalle complet après start_date
  • Programme à start_date + schedule
'start_date': datetime(2026, 2, 25, tz="UTC")
'schedule': @daily

Premier lancement possible : 26 février 2026

Introduction à Apache Airflow en Python

Passons à la pratique !

Introduction à Apache Airflow en Python

Preparing Video For Download...