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:

1
2
3
4
5
weekend_check = DayOfWeekSensor(
    task_id='weekend_check',
    week_day={'Saturday', 'Sunday'},
    use_task_execution_day=True,
    dag=dag)

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.

Did you enjoy reading this article?
Would you like to learn more about software craft in data engineering and MLOps?

Subscribe to the newsletter or add this blog to your RSS reader (does anyone still use them?) to get a notification when I publish a new essay!

Newsletter

Do you enjoy reading my articles?
Subscribe to the newsletter if you don't want to miss the new content, business offers, and free training materials.

Bartosz Mikulski

Bartosz Mikulski

  • Data/MLOps engineer by day
  • DevRel/copywriter by night
  • Python and data engineering trainer
  • Conference speaker
  • Contributed a chapter to the book "97 Things Every Data Engineer Should Know"
  • Twitter: @mikulskibartosz
Newsletter

Do you enjoy reading my articles?
Subscribe to the newsletter if you don't want to miss the new content, business offers, and free training materials.