Setting up the Magento cronjob (Magento 2)
This is a guide for Magento 2. For Magento 1 extensions and guides, please refer to Magento 1 Guides.
Please refer to the official Magento 2 documentation on how to set up the Magento cronjob: https://devdocs.magento.com/guides/v2.4/config-guide/cli/config-cli-subcommands-cron.html
Contents |
Troubleshooting
n98-magerun2: No job config found!
n98-magerun2 does not support cronjobs defined only via the database in core_config_data. These are perfectly fine cronjobs though. You just can't run them using n98-magerun2.
Stalled Cronjobs / No cronjobs scheduled
Please note you will ONLY see entries in the import/export execution log if it actually did something. If 0 orders are exported, or 0 stock level updates got processed, nothing is logged in the execution log.
Possible solutions for common cron issues:
- Do note that it can take up to 30 minutes or longer until Magento schedules a cronjob for the first time after changing the "Export Frequency" in a profile.
- Using the MageMojo_Cron module? Disabling it has helped other customers in the past. We're working with MageMojo to figure out what's wrong.
- Open your export/import profile that doesn't work automatically and click "Save" once to save the profile. The cronjob has now been inserted into the database and you should see it being scheduled within 15 minutes. Wait, as Magento takes some time to re-generate the cron schedule.
- If you are 100% sure that the Magento cronjob has been set up properly, you can try to check the "cron_schedule" table in the Magento database and look for "xtento_" cronjobs that have status "pending". Try deleting those rows from the table and then wait 15-30 minutes for the cron schedule to be regenerated.
- Check the core_config_data table and look for entries where "path" is like "crontab/%". Check if ANY of the entries (could be ANY job - not just XTENTO jobs) have invalid values in the "cron_expr" field, i.e., an invalid cron expression. This could cause ALL dynamic cronjobs to stop working. A valid cron expression looks like this:
* * * * *
or
*/5 0 * * *
or
0 0 * * *
An invalid cron expression could look like this for example:
* * * * * * (Too many parameters - must be 5 exactly)
or
00 02 * * * (5 parameters, but hour/minute must be specified using single digits, so 0 and 2 instead of 00 and 02)
Setting up cronjobs directly in crontab
For our import/export extensions, imports/exports can be directly started via the command line:
Order Export: php bin/magento xtento:orderexport:export 123 Product Export: php bin/magento xtento:productexport:export 123 Stock Import: php bin/magento xtento:stockimport:import 123 Tracking Import: php bin/magento xtento:trackingimport:import 123 Order Import: php bin/magento xtento:orderimport:import 123
Where 123 is the profile ID you want to run. This will execute the profile using the cronjob mode.
Simply set up an entry in crontab directly if you want to avoid the Magento cron scheduler and instead use crontab to schedule exports from there. When using crontab to run your exports, be sure to disable "Automatic Export" in the import/export profile as it could run twice otherwise.
Export / Import profiles do not trigger
Try flushing Magento cache, this might help.