Set up cron jobs
Magento uses cron jobs for numerous features to schedule activities. This topic provides information for configuring crons for
Magento Commerce Cloud projects using the
.magento.app.yaml file specifies the configuration for the default Magento cron jobs as well as any custom crons that you add to the following environments.
Starter plan–All environments including
Pro plan–Integration, Staging, and Production environments including
.magento.app.yaml file includes the following default crons configuration, which runs the default Magento cron jobs:
1 2 3 4 crons: cronrun: spec: "* * * * *" cmd: "php bin/magento cron:run"
We use only one cron for Magento Commerce Cloud projects because of the nature of read-only environments. This configuration is different from Magento Commerce, which has three default cron jobs. See Configure and run crons in the Magento Commerce documentation.
To verify cron configuration on Starter projects:
Log in to the Magento Commerce Cloud project environment using SSH.
Review the cron configuration in the
cronssection of the .magento.app.yaml configuration file.
Verify cron configuration on Pro projects
Magento added an auto-crons configuration option to all Pro plan projects to support self-service cron configuration on Staging and Production environments using the
.magento.app.yaml file. If this option is enabled, you can use crontab to review the cron configuration.
Although you can use crontab to review configuration on Pro plan projects, Magento does not use crontab to run cron jobs for Magento Commerce sites deployed on the Cloud platform.
To review cron configuration on Pro plan environments:
Log in to the Staging or Production environment using SSH.
List the scheduled cron processes.
crontab -lcommand returns a
Command not founderror, contact your Customer Technical Advisor (CTA) or Customer Success Manager (CSM) about enabling the auto-crons self-service configuration option on your Magento Commerce Cloud project.
The following example shows the crontab output for an environment that has only the default crons configuration:
1 2 3 4 5 6 7 8 username@hostname:~$ crontab -l # Crontab is managed by the system, attempts to edit it directly will fail. SHELL=/etc/platform/6fck2obu3244c/cron-run MAILTO="" # m h dom mon dow job_name * * * * * cronrun
Build a cron job
A cron job includes the schedule and timing specification and the command to run at the scheduled time. For example, the general format is:
1 * * * * * <command>
Magento uses a five value specification for a cron job. The numbers per each
* * * * * is as follows:
- Minute (0-59) For all Starter and Pro environments, the minimum frequency supported for crons is five minutes. You may need to configure settings in your Magento Admin.
- Hour (0-23)
- Day of month (1 - 31)
- Month (1 - 12)
- Day of week (0 - 6) (Sunday to Saturday; 7 is also Sunday on some systems)
00 */3 * * * runs every 3 hours at the first minute (12:00 am, 3:00 am, 6:00 am, and so on)
20 */8 * * * runs every 8 hours at minute 20 (12:20 am, 8:20 am, 4:20 pm, and so on)
00 00 * * * runs once a day at midnight
00 * * * 1 runs once a week on Monday at midnight.
The cron time specified in the
.magento.app.yaml file is based on the server timezone, not the timezone specified in the store configuration values in the Magento database.
When determining the scheduling of custom cron jobs, consider the time it takes to complete the task. For example, if you run a job every three hours and the task takes 40 minutes to complete, you may consider changing the scheduled timing.
On the Magento Cloud platform, you add custom cron job configuration to the
.magento.app.yaml file in the
crons section. The general format is
spec for scheduling and
cmd to specify the command or custom script to run.
For the command script, the format includes:
<path-to-php-binary> <magento install dir>/<script with command>
The following is an example cron job:
1 2 3 crons: spec: "00 */8 * * *" cmd: "/usr/bin/php /app/abc123edf890/bin/magento export:start catalog_category_product"
In this example,
/usr/bin/php. The install directory, which includes the Project ID is
/app/abc123edf890/bin/magento, and the script action is
Add custom cron jobs to your project
On the Magento Commerce Cloud platform, you configure custom cron jobs by adding them to the
.magento.app.yaml file in the
The default cron interval for all environments provisioned in the US-3, EU-3, and AP-3 regions is 1 minute. The default cron interval in all other regions is 5 minutes for Pro Integration environments and 1 minute for Pro Staging and Production environments. You cannot configure more frequent intervals than the default minimums.
On Magento Commerce Pro projects, the auto-crons feature must be enabled on your Magento Commerce Cloud project before you can add custom cron jobs to Staging and Production environments using
.magento.app.yaml. If this feature is not enabled, contact your Customer Technical Advisor (CTA).
To add custom crons:
In your local development environment, edit the
.magento.app.yamlfile in the Magento
cronssection, add your custom cron code in the following format:
1 2 3 4 5 6 7
crons: <cron_name_1>: spec: "<schedule_time>" cmd: "<schedule_command>" <cron_name_2>: spec: "<schedule_time>" cmd: "<schedule_command>"
For example, you can add a custom cron job to export the product catalog and configure it to run every eight hours, 20 minutes after the hour.
1 2 3 4 5 6 7
crons: magento: spec: '* * * * *' cmd: 'php bin/magento cron:run' productcatalog: spec: '20 */8 * * *' cmd: 'bin/magento export:start catalog_product_category'
Add, commit, and push code changes.
git add -A && git commit -m "cron config updates" && git push origin <branch-name>
Update custom cron jobs
To add, remove, or update a custom cron job, change the configuration in the
crons section of the
.magento.app.yaml file for the Integration environment. Then, test the updates in the Integration environment before pushing the changes to the Production and Staging environments.
Disable cron jobs
In some cases you might want to manually disable cron jobs before you complete maintenance tasks like reindexing or cleaning the cache to prevent performance issues. You can use the
ece-tools CLI command
cron:disable to disable all Magento cron jobs and stop any active cron processes.
To disable cron jobs:
Disable cron jobs and stop active cron processes.
After you complete any required maintenance tasks, ensure that you enable the cron jobs again.
Troubleshooting cron jobs
Magento has updated the Magento Commerce Cloud package to optimize cron processing on the Magento Commerce Cloud platform and to fix cron-related issues. If you encounter problems with cron processing, make sure that your project is using the most current version of the
ece-tools package. See Upgrades and patches.
You can review cron processing information in the application-level log files for each environment. See Application logs.
See the following Magento Support articles for help troubleshooting cron-related problems: