set cron job in custom module of magento

Magento allows you to schedule custom tasks in an XML configuration, in a similar manner to the UNIX crontab style. Here is an example from app/code/local/namespace/module/etc/config.xml:

<config>
       <crontab>
           <jobs>
               <namespace_module>
                    <schedule>
                        <cron_expr>0,15,30,45 * * * *</cron_expr>
                    </schedule>
                    <run>
                        <model>module/model::method</model>
                    </run>
                </namespace_module>
            </jobs>
        </crontab>
    </config>

That will run every 15 minutes on the quarter hour.

To execute all these configured tasks, the cron.php file located in the Magento root will need to be run periodically, for example every 15 minutes. Basically, this script will check if it needs to run any tasks, and if it needs to schedule any future tasks.

Leave a Reply

Your email address will not be published.