Skip to content

6. Weekday or Weekend Refresh, Then Publish

Difficulty: Medium · Topic: Branching

The DAG refresh_reports runs @daily from 2026-01-01 (no catchup). It picks how to refresh the reports from the day of the run (its logical date):

Write the choice as a branch task named choose (with @task.branch or BranchPythonOperator). The three other tasks are BashOperators.

Your DAG file is run in a simulation of the Airflow 3 scheduler against 5 scenarios, including hidden ones.

Sample scenario: Friday to Sunday

Deployed 2026-01-02 12:00 UTC, read at 2026-01-04 01:00 UTC.

Expected runs

Hints

Hint 1A branch callable returns the task_id to follow, or a list of task_ids. Every other task directly downstream of the branch is skipped.
Hint 2logical_date.weekday() is 0 for Monday and 6 for Sunday; logical_date.day is the day of the month. Name logical_date as a parameter and Airflow passes it in.
Hint 3With the default all_success, publish is skipped as soon as one upstream task is skipped, which is every day but the 1st. Look for a trigger rule that accepts skipped upstream tasks but not failed ones, and needs at least one success.

Learn the concepts

More Airflow problems

All Airflow problems · Learn Airflow