Magento 2 Cron

Magento 2 Cron

Magento 2 Cron tutorial on how to to configure and what is Cron needed for.

How Cron works #

Magento 2 Cron uses the hosting's server Cron for some of it's functionality. This is needed for processing essential parts of the application:

  • All Magento e-mails like Order Confirmation, Transactional Emails Newsletter sending - Magento 2 does not send these emails at once but queues them and sends in batches. If your store is not sending any order confirmation emails Cron running properly is a first point to check.

  • Catalog price rules updates.

  • Customer Alerts and Notifications - if a Customer chooses to be notified when a Product comes back in stock, or there is a price change for example, on the Product Page.

  • Generating a Sitemap - as you update the Product Catalog, for example add a new Product, the sitemap.xml can be left in a state where it's missing it, this is where cron processes a new Sitemap and adds the new Product.

  • Reindexing - changes to Products or Categories can be left behind as the index has old data stored.

  • Updates the Currency Rates

Cron Setup #

To setup the cron tasks in your system you can run:

$ bin/magento cron:install

The cron setup command can return either:

Crontab has been generated and saved

or if you already have the cron tasks installed:

Crontab has already been generated and saved

Cron Sample #

Crontab can be checked in your System via command line:

crontab -l

This will output something in the form below:

#~ MAGENTO START
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run | grep -v Ran jobs by schedule >> /var/www/html/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/update/cron.php >> /var/www/html/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento setup:cron:run >> /var/www/html/magento2/var/log/setup.cron.log
#~ MAGENTO END

Make sure /var/www/html/magento2/ above matches the path of your Magento Root folder.

Cron Run #

To trigger a Magento 2 Cron run you can execute the command line:

$ bin/magento cron:run

The output of cron run after execution should be:

Ran jobs by schedule.

Cron Test #

So you've setup Cron using the method above but you are not sure if it is really working ? Below are ways to test if Cron is running in your Magento 2 store.

Cron log #

SSH / FTP into your hosting and in the wwwroot/var/log/ folder check if any of these files exist:

  • cron.log
  • magento.cron.log
  • update.cron.log
  • setup.cron.log

Cron Table #

You can also check the cron tasks that ran or are scheduled in your Database by running following query:

select * from cron_schedule

The list returned will show when each task ran, when it finished (if it did):

- Job ID and code
- Status
- Created date
- Scheduled date
- Executed date
- Finished date 

Cron Disable / Remove #

To disabled or remove a Magento 2 Cron you can execute the command line:

$ bin/magento cron:remove

The output of the removal command after execution should be:

Magento cron tasks have been removed

Published: Dec 23, 2018. Updated: May 21, 2020.


Magento 2 Redis

Magento 2 Redis

Magento 2 Redis Tutorial, How to Install and Configure for Default Cache, Page Cache and Sessions Storage.

Read
Magento 2 Import

Magento 2 Import

Magento 2 Import tutorial and How To for Products Import, Categories Import, Customers Import or Tax Rates Import.

Read

Magento 2 Indexer

Magento 2 Indexer, what is it and why is it needed in your Magento 2 store and how do you reindex.

Read

Magento 2 SEO

We will help you with SEO ratings by providing some Magento 2 SEO Tips

Read

Magento 2 Extension

Magento 2 Extension tutorial, learn what is a Magento 2 Extension how to install or disable in your Magento store.

Read

Magento 2 Cache

Magento 2 Cache tutorial on different usage scenarios and why Cache should be enabled on your store.

Read
Contact
Hire us


Need help with Magento 2 Cron ?


Tech

Technologies we work with

Magento is an open-source e-commerce platform written in PHP
PHP is a popular general-purpose scripting language that is especially suited to web development.
MySQL is an open-source relational database management system.
Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability.
Varnish is an HTTP accelerator designed for content-heavy dynamic web sites as well as APIs.
Google Tag Manager is a free tool that allows you manage and deploy marketing tags on your website / app
Google Analytics is a web analytics service offered by Google that tracks and reports website traffic
Elasticsearch is a search engine based on the Lucene library.