0
0
Apache Airflowdevops~10 mins

Atomic operations in pipelines in Apache Airflow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a task that runs a Python function atomically in Airflow.

Apache Airflow
from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime

def my_task():
    print('Task running')

dag = DAG('my_dag', start_date=datetime(2024, 1, 1))

task = PythonOperator(task_id='run_my_task', python_callable=[1], dag=dag)
Drag options to blanks, or click blank then click option'
Amy_task
Bprint
CDAG
Ddatetime
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' instead of the function name.
Passing a function call like 'my_task()' instead of the function itself.
2fill in blank
medium

Complete the code to set the task to run only after the previous task finishes successfully.

Apache Airflow
task1 >> [1]
Drag options to blanks, or click blank then click option'
Atask1
Bdag
Ctask2
Dtask3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same task on both sides.
Using the DAG object instead of a task.
3fill in blank
hard

Fix the error in the code to ensure the task retries 3 times on failure.

Apache Airflow
task = PythonOperator(task_id='retry_task', python_callable=my_task, retries=[1], dag=dag)
Drag options to blanks, or click blank then click option'
ANone
B'3'
CTrue
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Passing retries as a string like '3'.
Passing a boolean value instead of a number.
4fill in blank
hard

Fill both blanks to create a DAG that runs daily and starts on January 1, 2024.

Apache Airflow
dag = DAG('daily_dag', schedule_interval=[1], start_date=[2])
Drag options to blanks, or click blank then click option'
A'@daily'
Bdatetime(2024, 1, 1)
C'@hourly'
Ddatetime(2023, 12, 31)
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@hourly' instead of '@daily'.
Using a string instead of a datetime object for start_date.
5fill in blank
hard

Fill all three blanks to create a task that runs a Python function, retries twice, and has a retry delay of 5 minutes.

Apache Airflow
from datetime import timedelta

task = PythonOperator(task_id='retry_task', python_callable=[1], retries=[2], retry_delay=timedelta(minutes=[3]), dag=dag)
Drag options to blanks, or click blank then click option'
Amy_task
B2
C5
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' instead of the function name.
Passing retries as a string.
Using a wrong value for retry_delay minutes.