How to setup a cron job in Magento module?

In your modules config.xml put the following:

<config>
    <global>
        <models>
            <roomstoryinvoicecron>
                <class>Roomstory_Invoice_Model</class>
            </roomstoryinvoicecron>                         
        </models>
    </global>
    <crontab>
        <jobs>
            <roomstoryinvoicecron>
                <schedule>
                    <cron_expr>*/10 * * * *</cron_expr>
                </schedule>
                <run>
                    <model>roomstoryinvoicecron/observer::setStatus</model>
                </run>
            </roomstoryinvoicecron>
        </jobs>
    </crontab>
</config>

In app/code/local/Roomstory/Invoice/Model/Observer.php add the following:

<?php
class Roomstory_Invoice_Model_Observer {
    public function setStatus() {
        Mage::log("WORKS!");
    }
}

Make sure logging is enabled and it should work, check the log to be sure 😉

Leave a Comment