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.
Bu egzersiz, kursun bir parçasıdır
Python ile Apache Airflow'a Giriş
Egzersiz talimatları
- Import the SMTP notifier object.
- Add a success callback attribute to the Dag.
- Send the notification to [email protected].
- Include a subject.
Uygulamalı etkileşimli egzersiz
Bu egzersizi bu örnek kodu tamamlayarak deneyin.
# 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()