Nick Jones

a magento developer (@nickj89) based in Bath

Magento How-to: Cron jobs for Modules

It’s inevitable that you’ll want to create a cron job for your Magento modules at some point. An obvious solution would be to make the user create a new crontab entry calling your script. There’s no need. Magento has cron functionality built in.

Simply edit your config.xml, adding the following:

<config>
    ...
    <crontab>
        <jobs>
            <shipwire_inventorysynch>
                <schedule><cron_expr>*/6 * * * *</cron_expr></schedule>
                <run><model>shipwire/api_inventorysynch::cron</model></run>
            </shipwire_inventorysynch>
        </jobs>
    </crontab>
</config>

When shipwire/api_inventorysynch::cron relates to the shipwire model namespace, api_inventorysynch relates to the model Meanbee_Shipwire_Model_Api_Invetorysynch and ::cron relates to the method cron() in that class.

Note: You need to make sure, of course, that the script ./cron.php, in the root of your Magento installation, has an entry in the crontab.

3 Responses to Magento How-to: Cron jobs for Modules

  1. Pingback: Magento Newsletters Not Sending + Solution | Edmonds Commerce Blog

  2. Awesome! Thanks for the info. It certainly helped me understand the logic of "namespace/model::method". Otherwise, the magento wiki or documentation is pretty weak.

  3. I am trying to find a way to turn some cron jobs off. The current site I am building only uses attributes for configurable products and not for layered navigation, so I am hunting for a way to speed things by shutting it off.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">