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.
The cron jobs you create are specific to the environment (glossary term, activate to view definition) 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.
To execute cron tasks on individual websites, you can use the Scheduled Jobs page in the Cloud Platform 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.
To create a cron job for your Factory environment:
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.
Click Add Cron job.
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.
In the field, enter how often you want to run the command using the .
You can manage your created cron jobs from the Cron jobs page, including editing or deleting cron jobs.
To edit an existing cron job:
The Cron jobs page displays your cron job with its new, revised values.
To delete a cron job value:
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:
For additional methods for debugging cron jobs, see Debugging cron.
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:
php-script command, setting the --script-path variable to the full path for your script.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.
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.
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.
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.
To execute cron tasks on individual websites, you can use the Scheduled Jobs page in the Cloud Platform 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.
To create a cron job for your Factory environment:
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.
Click Add Cron job.
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.
In the Interval field, enter how often you want to run the command using the cron time string format.
* */12 * * *).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.You can manage your created cron jobs from the Cron jobs page, including editing or deleting cron jobs.
To edit an existing cron job:
The Cron jobs page displays your cron job with its new, revised values.
To delete a cron job value:
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:
For additional methods for debugging cron jobs, see Debugging cron.
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:
php-script command, setting the --script-path variable to the full path for your script.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.
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.
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.
* */12 * * *).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.If this content did not answer your questions, try searching or contacting our support team for further assistance.
If this content did not answer your questions, try searching or contacting our support team for further assistance.