Information for: DEVELOPERS   PARTNERS

Managing cron tasks using the management console

Websites use cron to perform maintenance tasks to help ensure they remain healthy. Because websites need these maintenance tasks to run regularly, it’s helpful to have cron run on a recurring, automated schedule. To enable you to control the frequency of cron’s execution on your websites, Acquia Cloud Site Factory provides a Cron job page, allowing you to create, modify, and delete scheduled cron jobs.

Cron job page

The cron jobs you create are specific to the environment and stack in which they exist. For example, if you create a cron job on your Testing environment, that job will not exist on your Production environment unless you manually create the same job in the Production environment, using the same command line and schedule.

Your created cron jobs will execute in batches to prevent your server from overloading, and there is no guarantee that cron jobs will first run on specific websites. While cron jobs execute for an environment, your task logs will display one or more CronController message entries.

Important

To execute cron tasks on individual websites, you can use the Scheduled Jobs page in the Acquia Cloud interface. You must include the necessary --root options to specify the individual website. Cron tasks created in the Site Factory Management Console will execute on all websites in a multisite.

Creating a new cron job

To create a new cron job for your Factory environment, complete the following steps:

  1. Sign in to the Site Factory Management Console using an account with the platform admin role.

  2. In the admin menu, click Administration, and then, under Site Factory management, click the Cron link.

    The Cron jobs page displays and lists any pre-configured cron jobs in your Site Factory environment.

  3. Click Add Cron job.

    Create a cron job

  4. Enter a descriptive Name for your new cron job.

  5. Ensure the Enabled check box is selected. If you clear this check box, Acquia Cloud Site Factory will create the cron job, but will not execute the job based on its defined interval until you enable the job.

  6. If your Acquia Cloud Site Factory has more than one stack, select the stacks this cron job should apply to.

  7. In the Scope section, select from the following options based on your needs:

    • Sites with custom domains only
    • Sites without custom domains only
    • All sites
  8. In the Drush command field, enter the command you want to schedule for execution. For example, to schedule cron to run on your websites, enter cron in the field. Do not include a --uri option or Drush aliases, as Acquia Cloud Site Factory will add them to your command.

    Acquia recommends wrapping complex cron jobs in a shell script to reduce errors. For information about advanced options available for this field, see Evaluating PHP in cron jobs.

  9. In the Interval field, enter how often you want to run the command using the cron time string format.

    Note

    • Acquia recommends you run cron based on a 12-hour interval (for example, * */12 * * *).
    • Running cron jobs too frequently can affect performance.
  10. Based on your Drush command and its interval, enter a value for the Percentage of threads to use. Acquia recommends a value of 60 to balance the cron job’s utilization against any other cron jobs you may have already created for the environment.

  11. Click Continue.

Modifying or removing cron jobs

You can manage your created cron jobs from the Cron jobs page, including editing or deleting cron jobs.

Editing cron jobs

To edit an existing cron job, complete the following steps:

  1. Sign in to the Site Factory Management Console using an account with the platform admin role.
  2. In the admin menu, click Administration, and then, under Site Factory management, click Cron jobs link.
  3. Find the cron job you want to edit, and then in its Actions list, click Edit job.
  4. Modify the values for the cron job to meet your needs, and then click Continue.

The Cron jobs page displays your cron job with its new, revised values.

Deleting cron jobs

To delete a cron job value, complete the following steps:

  1. Sign in to the Site Factory Management Console using an account with the platform admin role.
  2. In the admin menu, click Administration, and then, under Site Factory management, click Cron jobs.
  3. Find the cron job you want to delete, and then in its Actions list, click Delete job.
  4. To confirm the deletion of the cron job, click Delete.

Troubleshooting cron jobs

If a Drush command fails, troubleshoot the cron job by reproducing the failure on the command line. To simplify troubleshooting, limit the scope of the command to a single website as shown in this example, replacing [DOMAIN_NAME] with the domain name and [DRUSH_COMMAND] with the command you are testing:

drush --root=/var/www/html/$AH_SITE_GROUP.$AH_SITE_ENVIRONMENT/docroot --uri=[DOMAIN_NAME] [DRUSH_COMMAND]

After executing the command for a single website, review the command-line output and Drupal Watchdog log for errors.

If your cron job requires logging, Acquia recommends one of the following options:

  • Adding code to the Drush command to send logging information to Drupal’s watchdog logs
  • Writing debugging information to a separate file

For additional methods for debugging cron jobs, see the Acquia Support Knowledge Base article on Debugging cron.

Evaluating PHP in cron jobs

ADVANCED – Poorly-formatted custom cron jobs can cause cron jobs to fail.

You can evaluate PHP as part of executing a cron job by placing a php-eval command in the Drush field, assuming all command-line arguments are escaped properly. For example, the following php-eval statement tests for a non-production environment, and executes a command if a module is installed there:

php-eval \"if (\\\$_ENV[\"AH_SITE_ENVIRONMENT\"] != \\\"01live\\\" && module_exists(\"nprode_import\")) nprode_import_start_import();\"

Acquia Cloud Site Factory will include the necessary --uri option and Drush alias.

For PHP statements too complicated to execute in a single php-eval statement, you can use one of the following approaches to execute your custom scripts with a cron job:

  • Convert the commands to a PHP file, and then execute the file using Drush with the php-script command, setting the --script-path variable to the full path for your script.
  • Convert your command into smaller individual commands, creating cron jobs to run each command in sequence. Before attempting this approach, contact Acquia Support with details about your proposed cron jobs to determine if your environment supports enough concurrency for this approach to succeed.