Search code examples
phpmagentocronmagento-1.9

cron job not running in custom magento module


I am adding a cron job inside my custom magento module. But magento is not executing my cron job

I have added crontab inside my module's config.xml and added the observer class inside model

I have tried even checking core_schedule table which show entries of the cron jobs,but my particular cron job seems to be missing.

Also entry has been made in crontab which has entry of cron.sh file in the root location

Hence, I am stuck on how to take it further from here and make it work.

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Uf_Rewards>
            <version>2.0.3</version>
        </Uf_Rewards>
    </modules>
    <frontend>
        <routers>
            <rewards>
                <use>standard</use>
                <args>
                    <module>Uf_Rewards</module>
                    <frontName>rewards</frontName>
                </args>
            </rewards>
        </routers>
        <layout>
            <updates>
                <rewards>
                    <file>rewards.xml</file>
                </rewards>
            </updates>
        </layout>
    </frontend>
    <global>
        <models>
            <rewards>
                <class>Uf_Rewards_Model</class>
                <resourceModel>rewards_resource</resourceModel>
            </rewards>
            <rewards_resource>
                <class>Uf_Rewards_Model_Resource</class>
            </rewards_resource>
        </models>
        <blocks>
            <rewards>
                <class>Uf_Rewards_Block</class>
            </rewards>
        </blocks>

    </global>
    <crontabs>
        <jobs>
            <rewards>
                <schedule>
                    <cron_expr>* * * * *</cron_expr>
                </schedule>
                <run>
                    <model>rewards/observer::sendEmails</model>
                </run>
            </rewards>
        </jobs>
    </crontabs>
</config>

Observer.php:

<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Uf_Rewards_Model_Observer extends Mage_Core_Model_Abstract
{
    public function sendEmails(){
        Mage::log('************************cron job*****************',NULL,'orderd.log',TRUE);
            }
}

Solution

  • Please try with the following code in your config.xml file. I just changed from <crontabs> to <crontab>

    <crontab>
        <jobs>
            <rewards>
                <schedule>
                    <cron_expr>* * * * *</cron_expr>
                </schedule>
                <run>
                    <model>rewards/observer::sendEmails</model>
                </run>
            </rewards>
        </jobs>
    </crontab>