cancel
Showing results for 
Search instead for 
Did you mean: 

How to override crontab.xml file to change cron time in Magento 2?

How to override crontab.xml file to change cron time in Magento 2?

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.

Tags (1)
5 REPLIES

Re: How to override crontab.xml file to change cron time in Magento 2?

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.

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: How to override crontab.xml file to change cron time in Magento 2?

Hi @Damian Culotta,

 

Thanks for the reply. I had tried and it is not working. Smiley Sad

Re: How to override crontab.xml file to change cron time in Magento 2?

Can you give me a few examples of which cronjobs you want to modify?

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: How to override crontab.xml file to change cron time in Magento 2?

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

Re: How to override crontab.xml file to change cron time in Magento 2?

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.

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"