Magento 2 Cron job is not working. What should I do?
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”
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)
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
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;
[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.
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
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.
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.
The Extension monitors code and configuration changes of your store, and automatically notifies you if these changes have negatively affected the key store indicators. If you change anything and find that either your store begins to work more slowly, or you suddenly experience new errors occurred, the extension will quickly notify you about it.