Understanding Cron Job schedules

The control panel offers a tool called Cron Jobs to periodically call a specified URL on your site. This is useful to execute scheduled tasks or perform background operations.

The control panel offers a “Minute and/or Hours” selector to choose when the cron job is executed. However, this configuration system is confusing and tends to behave in unexpected ways.

Recommended Schedules

Calling a URL once per hour

If you want like to execute a URL once per hour on the whole hour, the schedule to do so is Minutes: 59. The hours selector may be set to Hours: 0, Hours: 1 or be left empty.

With this schedule, the URL is called once per hour at the whole hour.

Calling a URL multiple times per hour

If you would like to call a URL multiple times per hour, like once every 15 minutes, the schedule to do so is: Minutes: 15. The hours selector may be set to Hours: 0, Hours: 1 or be left empty.

You can choose other schedules too, like every 5, 10, 20 or 30 minutes.

Calling a URL once every few hours

The current cron scheduling does not appear to support calling a URL less than once per hour.

If you only need to execute a cron job less frequently than that (like once per day), you can setup a cron job to execute every hour and implement a check to see the hour of the day. If the hour is a specified value (like 12), only then the cron logic is performed.

Good to know about the schedules

The cron schedule has a lot of caveats and unexpected behavior.

  • Cron jobs will be called once when they are added.
  • Cron jobs can sometimes run multiple times or not run at all. Do not expect cron jobs to always run at specified times.
    • Cron jobs tend to execute an additional time at the whole hour. This tends to happen quite often regardless of the configuration.
  • If you leave the Minute selector empty, the cron job will not run.
  • Selecting “Hours: 0”, “Hours: 1” or leaving the “Hours” setting empty seems to have identical effects: only the Minute schedule will be followed.
  • If you select a number greater than 2 for the Hours selector, the cron job will be executed according to the minute schedule, and another time every specified number of hours.
4 Likes