Operadores adicionales

Introducción a Apache Airflow en Python

Mike Metzger

Data Engineer

PythonOperator

  • Ejecuta una función/callable de Python
  • Similar a BashOperator, con más opciones
  • Puede pasar argumentos al código 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 )
Introducción a Apache Airflow en Python

Argumentos

  • Admite argumentos en las tareas
    • Posicionales
    • Con nombre
  • Usa el diccionario op_kwargs
Introducción a Apache Airflow en Python

Ejemplo de 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} )
Introducción a Apache Airflow en Python

EmailOperator

  • En la librería airflow.operators
  • Envía un email
  • Puede incluir componentes típicos
    • Contenido HTML
    • Adjuntos
  • Requiere configurar Airflow con los detalles del servidor de correo
Introducción a Apache Airflow en Python

Ejemplo de 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' )
Introducción a Apache Airflow en Python

¡Vamos a practicar!

Introducción a Apache Airflow en Python

Preparing Video For Download...