Opérateurs supplémentaires

Introduction à Apache Airflow en Python

Mike Metzger

Data Engineer

PythonOperator

  • Exécute une fonction/appelable Python
  • Semblable à BashOperator, avec plus d’options
  • Peut transmettre des arguments au code Python
from airflow.operators.python import PythonOperator

def printme(): print("This goes in the logs!")
python_task = PythonOperator( task_id='simple_print', python_callable=printme )
Introduction à Apache Airflow en Python

Arguments

  • Gère des arguments pour les tâches
    • Positionnels
    • Mots clés
  • Utiliser le dictionnaire op_kwargs
Introduction à Apache Airflow en Python

Exemple op_kwargs

def sleep(length_of_time):
  time.sleep(length_of_time)

sleep_task = PythonOperator( task_id='sleep', python_callable=sleep, op_kwargs={'length_of_time': 5} )
Introduction à Apache Airflow en Python

EmailOperator

  • Dans la bibliothèque airflow.operators
  • Envoie un e-mail
  • Peut inclure des éléments courants
    • Contenu HTML
    • Pièces jointes
  • Nécessite une configuration d’Airflow avec les paramètres du serveur e-mail
Introduction à Apache Airflow en Python

Exemple EmailOperator

from airflow.operators.email import EmailOperator

email_task = EmailOperator( task_id='email_sales_report', to='[email protected]', subject='Automated Sales Report', html_content='Attached is the latest sales report', files='latest_sales.xlsx' )
Introduction à Apache Airflow en Python

Passons à la pratique !

Introduction à Apache Airflow en Python

Preparing Video For Download...