Magento – How to set-up a cron job for multiple models in magento

cronmagento-1.9

I'm trying to set-up a cron job for multiple models. I have two methods (method1 and method2) in Model (observer.php) for which I want to set cron job. My code :

Config.xml file :

 <crontab>
        <jobs>            
        <erpbridge_update>
            <schedule>
                <cron_expr>* * * * *</cron_expr>
            </schedule>
            <run>
                <model>erpbridge/observer::method1</model>
            </run>

        </erpbridge_update>  
        <mss_erpbridge>
                <schedule>
                <cron_expr>* * * * *</cron_expr>
            </schedule>
                <run>
            <model>erpbridge/observer::method2</model>
            </run>
            </mss_erpbridge>

        </jobs>
    </crontab>

Name space is Mss and module name is Erpbridge, Cron job with the right module name working perfectly <mss_erpbridge> but this is not working </erpbridge_update>. When I set the same key for both <mss_erpbridge> then only the second works.

My query :

Is it possible to set a cron job for multiple Models if yes, How?

Best Answer

Deepak, may be at any xml file you have using erpbridge_update name cronjob.

I suggest to you use any another name for cronjob identofier event name.

As magento save the cronjob idenfier in cronjob table at db and basic of this table magento cronjob is excute. So, you cannot use name idenfier name for two cronjob.

For example from app/code/core/Mage/CatalogRule/etc/config.xml:

<config>
...
    <crontab>
        <jobs>
            <catalogrule_apply_all> <!-- this is  indentifier name which is save at db -->
                <schedule><cron_expr>0 1 * * *</cron_expr></schedule>
                <run><model>catalogrule/observer::dailyCatalogUpdate</model></run>
            </catalogrule_apply_all>
        </jobs>
...
    </crontab>
...
</config>
Related Topic