BranchDayOfWeekOperator¶
Use the BranchDayOfWeekOperator
to branch your workflow based on week day value.
empty_task_1 = EmptyOperator(task_id='branch_true')
empty_task_2 = EmptyOperator(task_id='branch_false')
empty_task_3 = EmptyOperator(task_id='branch_weekend')
empty_task_4 = EmptyOperator(task_id='branch_mid_week')
branch = BranchDayOfWeekOperator(
task_id="make_choice",
follow_task_ids_if_true="branch_true",
follow_task_ids_if_false="branch_false",
week_day="Monday",
)
branch_weekend = BranchDayOfWeekOperator(
task_id="make_weekend_choice",
follow_task_ids_if_true="branch_weekend",
follow_task_ids_if_false="branch_mid_week",
week_day={WeekDay.SATURDAY, WeekDay.SUNDAY},
)
# Run empty_task_1 if branch executes on Monday, empty_task_2 otherwise
branch >> [empty_task_1, empty_task_2]
# Run empty_task_3 if it's a weekend, empty_task_4 otherwise
empty_task_2 >> branch_weekend >> [empty_task_3, empty_task_4]