LoslegenKostenlos starten

Implementing an SmtpNotifier

Now that you've successfully created a failure callback, your team lead has asked that all successful Dag runs be sent via email to a team alias. After reviewing the Airflow documentation, you decide that using Airflow's built-in notifier framework is your best option.

The dag and task objects are already imported, the alert_on_failure callback function and the get_sales_data and process_sales_data tasks are already defined for you.

Diese Übung ist Teil des Kurses

<Kurs>Einführung in Apache Airflow mit Python</Kurs>
Kurs ansehen

Übungsanweisungen

  • Import the SMTP notifier object.
  • Add a success callback attribute to the Dag.
  • Send the notification to [email protected].
  • Include a subject.

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Import the notifier
from airflow.providers.smtp.notifications.smtp import ____

# Add a success callback notifier
@dag(dag_id='sales_etl_dag',
     on_failure_callback=alert_on_failure,
     ____=SmtpNotifier(
         to="____",
         from_email="[email protected]",
         ____="sales_etl_dag run succeeded!"
     ))
def sales_etl_dag():
  get_sales_data() >> process_sales_data()
  
sales_etl_dag()
Code bearbeiten und ausführen