Unlike in Magento 1, cron performs critically important tasks in Magento 2. In the native installation, there are 26 modules that use cron for 53 different jobs. You can get acquainted with the full list of modules below in the text.

Practically, all reindex processes work in the cron process. Newsletters, product alerts, page cache, etc

Moreover, most third-party extensions use cron and some extensions simply do not run if the cron is not configured or operates in the wrong way.

How to determine if cron is not working?

a) install Magento 2 Cron Scheduler extension

At present, there are many extensions that perform complex checking and visualization of cron task performance. You can easily find them with the inquiry “Magento 2 cron scheduler extension” or “Magento 2 cron module”

Magento 2 Cron Scheduler Extension

b) To check directly in the database If you do not want to install an additional extension, it is enough for you to open up DB (via phpMyAdmin, for example) and run a simple SQL query:

SELECT MAX(executed_at) FROM cron_schedule

If cron is working correctly, you get results in near real time (max 5 min deviation) (I hope I didn't change the meaning, but it didn't make any sense before)

SQL Query to cron_schedule table

Another useful SQL query that returns the list of log errors:

SELECT job_code, messages FROM cron_schedule WHERE messages IS NOT NULL

Cron job is not working. What should I do?

In Magento 2, the cronjob performance is related to the command bin/magento cron:run

Connect via ssh and run the command crontab -l to obtain the list of active cronjobs. After running the command crontab -l > crontab.cfg, you will record the current configuration to a file for the following editing. The command crontab crontab.cfg, vice versa installs the configuration from the file.

Also, you can set up cron via Cpanel, the same configurations, however, via web interface (Cpanel > Cron Jobs or Cpanel > Scheduled Tasks)

If you already have cronjob or you only have to add it , we recommend to use the following command:

* * * * * php -f [store root]/bin/magento cron:run >> [store root]/var/log/magento.cron.log 2>&1;

where [store root] is the root directory with installed Magento.

This command is slightly different from a command given in Magento 2 manuals. However, it also brings a wide variety of unquestionable advantages: ANY error and any successful performance will be recorded in a log file.

After new cronjob configuring, within the next minute, the log file store [root]/var/log/magento.cron.log with the error text or successful performance notification “Ran jobs by schedule.” will appear.

Magento 2 Cron Log File

If the file does not register within the next 1 minute, it means the wrong path to the root directory or no permissions to write to the directory were implemented var/log/

Conclusion

Cron is vitally important, which is why you should pay extra attention to it and make sure that it is operating correctly. Cron error checking is implemented in our Stability Suite for Magento 2, which will also notify you about the errors.

After Conclusion

The list of Magento 2 extensions that use cron is as follows: NewRelicReporting, ProductAlert, CatalogRule, Integration, Backup, Sales, Persistent, Newsletter, Directory, Analytics, Shipping, Security, Catalog, Captcha, Backend, Sitemap, Tax, Customer, Paypal, Indexer.

Mirasvit extensions that use cron: Search, SearchSphinx, Misspell, Stability, Rewards, Affiliate, Email, Report, Helpdesk, RMA, Store Credit.

Related Posts
Blog For Magento 2 Store: Extension or Wordpress - How To Choose The Right Solution? Sphinx Search Ultimate VS Elastic Search Ultimate Making the right choice for your Magento Store: Magento extensions, Magento custom development, or both.

Enjoyed the Read?

Don’t miss our next article!