EmailOperator and dependencies
Now that you've successfully defined the PythonOperators for your workflow, your manager would like to receive a copy of the parsed JSON file via email when the workflow completes. The previous tasks are still defined and the DAG process_sales_dag
is configured. Please note that this task uses the older DAG definition method and is added for you.
This exercise is part of the course
Introduction to Apache Airflow in Python
Exercise instructions
- Import the class to send emails.
- Define the Operator and add the appropriate arguments (
to
,subject
,files
). - Set the task order so the tasks run sequentially (Pull the file, parse the file, then email your manager).
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import the Operator
from ____ import ____
# Define the task
email_manager_task = ____(
task_id='email_manager',
____='[email protected]',
____='Latest sales JSON',
html_content='Attached is the latest sales JSON file as requested.',
____='parsedfile.json',
dag=process_sales_dag
)
# Set the order of tasks
pull_file_task ____ parse_file_task ____ email_manager_task