Introduction to Apache Airflow in Python
Mike Metzger
Data Engineer
Using @task.branch
Runs a python function to return the next task id (or list of ids) to follow
@task.branch
def branch_task(logical_date):
if int(logical_date.month) % 3 == 0:
# Months 3 - March, 6 - June, 9 - September, 12 - December
return 'end_of_quarter_task'
else:
# All other months
return 'regular_monthly_task'
@task.branch def branch_task(logical_date): if int(logical_date.month) % 3 == 0: # Months 3 - March, 6 - June, 9 - September, 12 - December return 'end_of_quarter_task' else: # All other months return 'regular_monthly_task'start_task >> branch_task >> end_of_quarter_task >> end_of_quarter_task2branch_task >> regular_monthly_task >> regular_monthly_task2



ds - Logical date with dashes YYYY-MM-DDds_nodash - Logical date without dashes YYYYMMDDprev_data_interval_start_success - Date of last successful Dag runIntroduction to Apache Airflow in Python