BranchDayOfWeekOperator

Use the BranchDayOfWeekOperator to branch your workflow based on week day value.

airflow/example_dags/example_branch_day_of_week_operator.py[source]

  1. empty_task_1 = EmptyOperator(task_id="branch_true")
  2. empty_task_2 = EmptyOperator(task_id="branch_false")
  3. empty_task_3 = EmptyOperator(task_id="branch_weekend")
  4. empty_task_4 = EmptyOperator(task_id="branch_mid_week")
  5. branch = BranchDayOfWeekOperator(
  6. task_id="make_choice",
  7. follow_task_ids_if_true="branch_true",
  8. follow_task_ids_if_false="branch_false",
  9. week_day="Monday",
  10. )
  11. branch_weekend = BranchDayOfWeekOperator(
  12. task_id="make_weekend_choice",
  13. follow_task_ids_if_true="branch_weekend",
  14. follow_task_ids_if_false="branch_mid_week",
  15. week_day={WeekDay.SATURDAY, WeekDay.SUNDAY},
  16. )
  17. # Run empty_task_1 if branch executes on Monday, empty_task_2 otherwise
  18. branch >> [empty_task_1, empty_task_2]
  19. # Run empty_task_3 if it's a weekend, empty_task_4 otherwise
  20. empty_task_2 >> branch_weekend >> [empty_task_3, empty_task_4]

DayOfWeekSensor

Use the DayOfWeekSensor to sense for day of week.

airflow/example_dags/example_sensors.py[source]

  1. t10 = DayOfWeekSensor(
  2. task_id="week_day_sensor_failing_on_timeout", timeout=3, soft_fail=True, week_day=WeekDay.MONDAY
  3. )