---
title: "Managing cron tasks using the management console"
date: "2024-02-14T06:18:38+00:00"
summary: "Easily manage cron tasks for your Drupal sites using Site Factory's Management Console. Create, modify, and delete scheduled jobs to maintain website health and automate maintenance across your multisite environment."
image:
type: "page"
url: "/site-factory/managing-cron-tasks-using-management-console"
id: "5430ba92-fe4c-45cd-98f3-e22aa5621207"
---

Websites use cron to perform maintenance tasks to help ensure they remain healthy. Since 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, Site Factory provides a **Cron jobs** page, allowing you to create, modify, and delete scheduled cron jobs.

![Configuring cron job](https://acquia.widen.net/content/ubowgudeat/jpeg/site-factory_configuring-cron-1.jpeg?position=c&color=ffffffff&quality=80&u=u1mnox)

The cron jobs you create are specific to the environment and [stack](/site-factory/stacks) 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](/site-factory/monitor/tasklog) 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 [Cloud Platform interface](/acquia-cloud-platform/manage-apps/cron). 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 cron job
-------------------

To create a cron job for your Factory environment:

1.  [Sign in](/site-factory/login) to the Site Factory Management Console using an account with the [platform admin](/site-factory/manage/users/admin/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**.
    
    ![Configuring cron job](https://acquia.widen.net/content/ubowgudeat/jpeg/site-factory_configuring-cron-1.jpeg?position=c&color=ffffffff&quality=80&u=u1mnox)
    
4.  Enter a descriptive **Name** for your new cron job.
5.  Ensure the **Enabled** checkbox is selected. If you clear this checkbox, 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 Site Factory has more than one [stack](/site-factory/stacks), 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 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](#acsf-php-in-cron).
    
9.  In the **Interval** field, enter how often you want to run the command using the [cron time string format](/acquia-cloud-platform/help/92596-cron-time-string-format "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. For more information, see [Allocating resources for cron jobs](#acsf-cron-percentage-threads).
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:

1.  [Sign in](/site-factory/login) to the Site Factory Management Console using an account with the [platform admin](/site-factory/manage/users/admin/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:

1.  [Sign in](/site-factory/login) to the Site Factory Management Console using an account with the [platform admin](/site-factory/manage/users/admin/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](/acquia-cloud-platform/monitor-apps/logs/drupal-watchdog) 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 [Debugging cron](/acquia-cloud-platform/help/93006-debugging-cron "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();\"

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](/service-offerings/support#contact-acquia-support) with details about your proposed cron jobs to determine if your environment supports enough concurrency for this approach to succeed.

Allocating resources for cron jobs
----------------------------------

Site Factory lets you specify the amount of resources that your cron jobs can utilize. To do so, you can use the **Percentage of threads to use** field while creating a [new cron job](#acsf-create-cron).

The **Percentage of threads to use** value dictates the amount of resources that your cron job uses out of the aggregate resources of all web servers. The impact of this value is on how often a specific web server can run the workload and is dependent on server resources and the command being run. As the same servers distribute web content, improper setting of this value can affect site responsiveness and availability.

Important

If you set **Percentage of threads to use** to a low value, your cron jobs may not run.

Each web server running your sites have two slots of workload. The **Percentage of threads to use** value indicates how many of these slots are used to run a particular cron command.

For example, you have 9 web servers distributing site content and a cron job where **Percentage of threads to use** is set to 60. There are 18 available slots. 60% of 18 is 11 slots on which the command can run, rounded to the nearest integer. When a cron task needs to run, at any given time, 11 commands run, evenly distributed across the 9 webs with a maximum of 2 commands per server.