I will need to change time of all the default cron job so I will need to change in crontab.xml file. Now I will need to override the crontab.xml file so I can make Magento 2 safe upgrade.
Hi @jigs_exe,
I didn't tried but what if you create your own module. COnfigure the <sequence> into you module's etc/module.xml file and put your moudle at the very end of the list.
Then, create the crontab.xml file and use the same names than the original cronjobs. The idea it should be to override the list of cronjobs.
As I said, I didn't tried but maybe this could help.
Can you give me a few examples of which cronjobs you want to modify?
I will need to change the time of all below crontab.xml files.
/vendor/magento/module-persistent/etc/crontab.xml
/vendor/magento/module-catalog/etc/crontab.xml
/vendor/magento/module-security/etc/crontab.xml
/vendor/magento/module-customer/etc/crontab.xml
/vendor/magento/module-sales/etc/crontab.xml
/vendor/magento/module-catalog-rule/etc/crontab.xml
/vendor/magento/module-sales-rule/etc/crontab.xml
Thanks,
/vendor/magento/module-tax/etc/crontab.xml
Hi @jigs_exe,
I've build a simple module and added the crontab.xml file.
Into the file I've added this (just an example):
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"> <group id="default"> <job name="aggregate_sales_report_tax_data" instance="Magento\Tax\Model\AggregateSalesReportTaxData" method="invoke"> <schedule>* * * * *</schedule> </job> </group> </config>
And then tested with:
bin/magento cron:run
The job was added at 16:29, but if you take a look at the original file:
/vendor/magento/module-tax/etc/crontab.xml
The original definition is:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"> <group id="default"> <job name="aggregate_sales_report_tax_data" instance="Magento\Tax\Model\AggregateSalesReportTaxData" method="invoke"> <schedule>0 0 * * *</schedule> </job> </group> </config>
So the main idea (override the cron definition with a custom module) should work.
Damian, your solution works fine, I have tested it on my machine. Both Magento itself and our third party Cron Scheduler recognize the new schedule from the override module!
One small thing is that because the custom module extends the original configuration, you can leave out some of the unnecessary parts, like `instance` and `method` as they are already defined in the original crontab. You only need the `name` property to extend it.
So the file could look a bit cleaner like this:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"> <group id="default"> <job name="aggregate_sales_report_tax_data"> <schedule>0 3 30 2 *</schedule> </job> </group> </config>