Tâches Airflow

Introduction à Apache Airflow en Python

Mike Metzger

Data Engineer

Tâches

Les tâches sont :

  • Des instances d’opérateurs
  • En général affectées à une variable en Python
    example_task = BashOperator(task_id='bash_example',
                              bash_command='echo "Example!"')
    
  • Référencées par le task_id dans les outils Airflow
Introduction à Apache Airflow en Python

Dépendances de tâches

$$

  • Définissent un ordre d’exécution des tâches
  • Non obligatoires pour un workflow, mais généralement présentes
  • Appelées tâches upstream ou downstream
  • Depuis Airflow 1.8, définies avec les opérateurs bitshift
    • >>, opérateur upstream
    • <<, opérateur downstream
Introduction à Apache Airflow en Python

Upstream vs Downstream

Upstream signifie avant

Downstream signifie après

Introduction à Apache Airflow en Python

Dépendance simple entre tâches

# Define the tasks
task1 = BashOperator(task_id='first_task',
                     bash_command='echo 1'
                    )

task2 = BashOperator(task_id='second_task', bash_command='echo 2' )
# Set first_task to run before second_task task1 >> task2 # or task2 << task1
Introduction à Apache Airflow en Python

Dépendances des tâches dans l’UI Airflow

vue DAG sans dépendances

Introduction à Apache Airflow en Python

Dépendances des tâches dans l’UI Airflow

vue DAG sans dépendances, repères des tâches

Introduction à Apache Airflow en Python

Dépendances des tâches dans l’UI Airflow

DAG avec dépendance simple

Introduction à Apache Airflow en Python

Dépendances multiples

Dépendances en chaîne :

task1 >> task2 >> task3 >> task4

Dépendances mixtes :

task1 >> task2 << task3

ou :

task1 >> task2
task3 >> task2

dépendances en chaîne

dépendances mixtes

Introduction à Apache Airflow en Python

Passons à la pratique !

Introduction à Apache Airflow en Python

Preparing Video For Download...