Why does the DayOfWeekSensor exist in Airflow?

This article is a part of my "100 data engineering tutorials in 100 days" challenge. (98/100)

I was surprised when I saw the DayOfWeekSensor in Airflow. Why is it here? Is it for the people who don’t know how to choose a day of the week in the CRON expression?

In the documentation, we see an example which looks like this:

weekend_check = DayOfWeekSensor(
    week_day={'Saturday', 'Sunday'},

It is strange. We can get the same result using a cron expression, for example: 0 10 * * 6-7.

So what are the possible use-case for the DayOfWeekSensor? I found two of them:

First, putting a sensor that waits for a specific day of the week is more explicit than tweaking the cron expression, so it is easier to spot that this DAG runs only on weekends.

Second, in the case of DAGs that run for multiple days, we may have a DAG that starts on Monday, runs some code for a few hours, and needs to wait until Wednesday to do something else. Still, for whatever reason, we don’t want to split that DAG into two separate DAGs running on different days.

To be honest, I have no idea what is the usage of this sensor. Do you know? Let me know.

Would you like to help fight youth unemployment while getting mentoring experience?

Develhope is looking for tutors (part-time, freelancers) for their upcoming Data Engineer Courses.

The role of a tutor is to be the point of contact for students, guiding them throughout the 6-month learning program. The mentor supports learners through 1:1 meetings, giving feedback on assignments, and responding to messages in Discord channels—no live teaching sessions.

Expected availability: 15h/week. You can schedule the 1:1 sessions whenever you want, but the sessions must happen between 9 - 18 (9 am - 6 pm) CEST Monday-Friday.

Check out their job description.

(free advertisement, no affiliate links)

Remember to share on social media!
If you like this text, please share it on Facebook/Twitter/LinkedIn/Reddit or other social media.

If you want to contact me, send me a message on LinkedIn or Twitter.

Bartosz Mikulski
Bartosz Mikulski * MLOps Engineer / data engineer * conference speaker * co-founder of Software Craft Poznan & Poznan Scala User Group

Subscribe to the newsletter and get access to my free email course on building trustworthy data pipelines.