Cron for Drupal

Understanding how Pantheon cron execution and cron management works on your Drupal site.


Cron is a time-based task scheduler that can be configured to automatically execute tasks without any manual involvement beyond the initial configuration.

Cron will always run unless all jobs are specifically set to 'Off' via Elysia or Ultimate Cron modules. Cron will also not run via Drush if a cron key is set with Elysia.

Both Drupal core and many contributed modules have tasks that need to be performed on a regular basis. You can configure when and how often cron executes the tasks.

Note

Containers on Pantheon are automatically spun down following a period of inactivity, then spun back up once a web request is made. Cron is not run on idle containers that have been spun down. For details, see All About Application Containers.

Pantheon Cron Execution

Pantheon executes cron once an hour on every environment to allow Drupal to perform scheduled tasks. This generally occurs within 5 to 10 minutes of half past each hour: 4:30pm, 5:30pm, 6:30pm, etc.

Typically cron is triggered via a browser/page request or crontab. However, Pantheon uses the following to automatically trigger cron on the platform:

drush pantheon_cron 3600

Technically, the command bootstraps your site and invokes drupal_cron_run, similar to how Drupal cron runs normally.

Manage Cron

You can manage cron via Drupal's admin interface at admin/config/system/cron.

There are a couple of ways to interact with cron on Pantheon. One way is to execute cron manually from the Drupal admin interface.
Drupal admin configure cron Click Run cron to run all scheduled tasks. Click Run Cron Alternatively, you can run all scheduled cron tasks with the following Terminus command:

terminus drush <site>.<env> -- cron

To ensure that cron tasks have been run, check the reports via the Drupal Admin interface at Reports > Recent Log Messages.  Reports--->Recent Log Messages If cron has run recently, entries will appear in the log. The two entries in the screenshot below show that cron has run and a cron task called "cron_example". Cron log entry in reports

Run Cron More Often

While Pantheon doesn't provide a mechanism for custom scheduling of cron tasks, the platform will automatically execute drush pantheon_cron 3600 once an hour, usually within 5 to 10 minutes of half past each hour (4:30pm, 5:30pm, 6:30pm, etc).

If the site has not been accessed through the web by a visitor for at least two hours, the platform suspends the associated services until it's accessed again and cron will not run.

There is a two-part workaround; first, keeping the site awake, then using a different mechanism for executing cron tasks.

To keep the site active, some users have used https://www.pingdom.com/ to access their site as often as once a minute. In conjunction, the use of the Drupal module https://www.drupal.org/project/elysia_cron allows for granular control over cron scheduling and execution with both an user interface and API.

By having pingdom visit the site once a minute like a visitor, the site stays active and elysia_cron has an opportunity to act every minute (if it needs to).

This combination is not officially supported by Pantheon, but has worked for some of our customers with similar needs.

As an alternative solution if you have anything that is executing a cron on your own server, you can invoke Drush commands remotely using Terminus, including Drush cron, to trigger scheduled operations.

Another very effective solution is to leverage a service such as EasyCron. You can set custom schedules, notifications, and logging through their web interface or through their EasyCron module. The unique URL to kick off cron externally can be found at /admin/config/system/cron

Disable Cron

To disable Drupal's standard cron:

  1. Navigate to Configuration > System > Cron within the admin interface.
  2. Select Never from the "Run cron every" drop-down menu.
  3. Click save configuration:

    Stop cron from running

Note

This configuration disables cron execution in Drupal, but it does not affect Pantheon's cron execution at the platform level which runs every hour on all environments.

Drupal 7 sites using the Elysia Cron contrib module to extend the standard cron can globally disable it in the module's settings:

disable cron globally by Elysia Cron

Troubleshooting Cron

Why didn't cron run?

The most common causes are:

What is the maximum execution time of cron?

The maximum execution time of cron is 180 seconds (3 minutes).

How can I find out when cron last ran?

You can check the log messages through the Drupal Admin interface.

You can also use Terminus to see when cron was last run with the following command:

terminus drush <site>.<env> -- wd-show --type='cron'

Resources