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):
- Monday to Friday:
full_refresh(refresh --mode full --date {{ ds }}, about 3 minutes). - Saturday and Sunday:
light_refresh(refresh --mode light --date {{ ds }}). - On the 1st of the month, whatever the weekday: both.
- Then
publish(publish --date {{ ds }}) runs once every refresh that ran has succeeded. If a refresh that ran failed,publishmust not run.
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
- Run at 2026-01-02 00:00 UTC: success. full_refresh success, light_refresh skipped, publish success
- Run at 2026-01-03 00:00 UTC: success. full_refresh skipped, light_refresh success, publish success
- Run at 2026-01-04 00:00 UTC: success. full_refresh skipped, light_refresh success, publish success
Hints
Hint 1
A 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 2
logical_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 3
With the defaultall_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
- Trigger rules and run state · 5 min read. When a task runs after its upstream tasks fail or skip, and how a run gets its final state.
- Branching and short-circuiting · 4 min read. Choose a path at run time, skip the rest, and join the branches back together.