Setting up a scheduled task (cron job)
A scheduled task runs a script at a fixed interval. Simple to create, and easy to set up badly.
What it is for
Backups, sending email, cleaning up, synchronising with an external system. Everything that has to happen without somebody clicking.
Do not run it too often
A task every minute that takes two minutes overlaps itself. That loads your server and causes double processing. Choose the frequency to match the run time.
Build in a lock
A mechanism preventing a second start while the first is running. It is the most effective protection against duplicates.
Know that it ran
A silent task that fails is the worst case: nothing happens and nobody knows. Record the result, and alert if it has not run on time.
Mind the time zone
The server does not necessarily follow your local time. A task set for midnight may run at one in the morning, which matters for daily reports.