Schedule background task

What I’m trying to do:
Is it possible to schedule a background task only on weekdays, or for example only on Monday and Wednesday? Can we somehow use CRON expressions to define the schedule?

I guess I could schedule it once per day and write the logic into the background task, but there might be an easier way?

Yep, that’s the way to do it!

3 Likes

Example:

from datetime import datetime as dt

# Datetime Weekday starts at 0 for Monday
if dt.today().weekday() not in (0, 2): # (Monday, Wednesday)
    return
5 Likes