Using Cron to schedule tasks

To help your website to run more efficiently, you should conduct regular website maintenance. You can automate maintenance tasks or jobs to run at scheduled intervals using the Cron page at Cloud > Cron.

Scheduled jobs are specific to the website environment that they're created in. While you cannot create a job that executes a command across multiple environments based on the same schedule, you can create a job for each environment, with each of these jobs using the same command line and schedule.

You should use the Cloud > Cron page for scheduled jobs, rather than the default Drupal 7 cron or any of the contributed Cron modules, such as Elysia Cron or Ultimate Cron. Compared to other Cron solutions, using the Cloud > Cron page is more reliable and provides extensive and integrated logging for Acquia Cloud websites.

The default Drupal 7 cron (poor man's cron) is enabled by default and you should disable it. To do this, go to http://[site_URL]/admin/config/system/cron, and in the Run cron every list, click Never. The default Drupal 7 cron is triggered by website activity, so relying on Acquia Cloud ensures that cron jobs are run on the schedule you specify, and not just when the website is visited. This both improves reliability and avoids the performance reduction on page requests.

If you do not have an Acquia Cloud subscription, but have an Acquia Basic subscription (which means your website is not hosted by Acquia Cloud), you can configure how often Cron runs from the Subscription > Site Grouping page. For more information, read Configuring cron for Basic subscriptions.

Creating scheduled jobs

To create a new cron job for an environment:

  1. Sign in to Acquia and open the Cloud > Cron page for your website.

    Cron page

  2. Click Add cron job for an environment.
  3. In the Add cron job to [env] dialog, enter a descriptive name for the job in the Name field.

    Add a cron job

  4. In the Cron command field, enter the command that you want to have Acquia Cloud regularly run for the environment. You can enter any commands that are allowed from an SSH connection to the website environment. A command cannot be longer than 255 characters. If you need to execute a command longer than that, you should incorporate it into a shell script that you run under cron.

    For some common Cron examples that you can use in this field, see the Using Cron command examples section on this page.

    You should test commands using SSH on your Acquia Cloud server to make sure they work before adding them as automated cron commands.

  5. Select how often you want to run the command from the menus in the Command frequency section:
    • Every minute
    • Every hour, at a number of minutes past the hour
    • Every day, at a certain time
    • Every week, at a certain day of the week and time of day
    • Every month, at a certain day of the month and time of day
    • Every year, at a certain month, day of the month, and time of day

    As an alternative, you can enter the Cron frequency as a string. For more information, see Cron time string format.

  6. Click Add.

After you create a new job, Acquia Cloud displays the job in the list of Cron jobs for the environment in which it was created.

Managing scheduled jobs

Each job that you create on the Cron page has links to help you manage the job, which allow you to do the following:

  • Suspend - Stops the scheduled job from running until you click Resume.
  • Edit - Opens a window that allows you to change the attributes of the scheduled job. After you make your changes, click Update.
  • Remove - Opens a window that deletes the scheduled job when you click Remove. If you remove a scheduled job, you cannot recover it, and you must manually re-create it to restore the job.

Cron and memory limits

Two approaches in using drush cron are to use the Acquia Cloud wrapper script for drush cron or to execute drush cron directly. These approaches have different memory limits. When you use the Acquia cron wrapper, the cron job uses the PHP memory limit for your environment (by default, 128 MB). When you use cron directly, it uses the command line process memory limit, which is 512 MB. If you find that your cron jobs fail to complete, try defining them to use drush cron directly to take advantage of this higher memory limit. For related information, see Debugging cron.

Cron command examples

Use the following examples as you create scheduled jobs for your website's environments.

Using "drush cron"

To use drush cron for enhanced Cron performance, select from the following methods:

In each of these examples:

  • [site] is the name of your website on Acquia Cloud (as listed on the Cloud > Users and keys page).

    To find your [site] name, sign in to Acquia and go to Cloud > Users and keys. The site name is the value before the ampersand ( @ ) in the SSH command line.

  • [env] is your environment (usually one of dev, test, or prod).
  • [site_URL] is your website's URL (as listed on the Cloud > Domains page). If you are using Drupal multisite, your cron jobs are specific to each website in the multisite installation. Use the URL of the website in the installation that you wish to target.

Use the Acquia Cloud wrapper script for drush cron

Use a cron command like this:

/usr/local/bin/ [site].[env] http://[site_URL]

Note that you don't need to append a cron_key to the website URL. The output of drush cron is logged to a file with a name like /var/log/sites/[site].[env]/logs/[server]/drush-cron.log. For example, if your site name was example, the log file for the prod environment might be named /var/log/sites/

Execute drush cron directly

/usr/local/bin/drush @[site].[env] -dv -l http://[site_URL]  cron 
  &>> /var/log/sites/${AH_SITE_NAME}/logs/$(hostname -s)/drush-cron.log

In this example, &>> /var/log/sites/${AH_SITE_NAME}/logs/$(hostname -s)/drush-cron.log logs the cron output to a drush-cron.log file in the server's logs directory. As already noted, cron jobs should always include a logging statement, as in this example.

Executing a shell script

You can create cron jobs to execute shell scripts that you've written.

For this example we'll assume that you've added scripts/ to your repository.


where [site].[env] is your website and environment.

Sign in to vote or comment