Once a script works, someone asks for it every morning. A scheduler such as cron, Windows Task Scheduler or a CI pipeline starts it, and from then on nobody is watching. The script itself has to be safe to run unattended.
This lesson covers the logic schedulers don't do for you:
- The next run time, with weekends and "exactly now" handled.
- UTC versus local time. Servers usually run in UTC; the people reading the report don't.
- Catching up on runs missed while a laptop slept.
- A lock file, so two runs never overlap, and a rule for locks left by a run that crashed.
- State, so a report goes out once per day even when the job runs twice.
Your functions take now or today as a parameter instead of reading the clock, which is what makes them testable.
Out: datetime(2026, 3, 2, 2, 0, tzinfo=timezone.utc). 06:00 in Dubai is 02:00 UTC, so cron on a UTC server says hour 2.