2

I have the following in config.xml in order to set up a cronjob with magento

<crontab>
    <jobs>
        <mycompany_mymodule>
            <schedule>
                <cron_expr>* * * * *</cron_expr>
            </schedule>
            <run>
                <model>mymodule/observer::editEntries</model>
            </run>
        </mycompany_mymodule>
    </jobs>
</crontab>

my controller is:

class Mycompany_Mymodule_Model_Observer{
    public function editEntries() {
        /****************/
    }
}

and i am getting the following error:

'exception ''Mage_Core_Exception'' with message ''Invalid callback: mymodule/observer::editEntries does not exist'' in C:\xampp\htdocs\magento\app\Mage.php:595
Stack trace:
#0 C:\xampp\htdocs\magento\app\code\core\Mage\Cron\Model\Observer.php(301): Mage::throwException(''Invalid callbac...'')
#1 C:\xampp\htdocs\magento\app\code\core\Mage\Cron\Model\Observer.php(72): Mage_Cron_Model_Observer->_processJob(Object(Mage_Cron_Model_Schedule), Object(Mage_Core_Model_Config_Element))
#2 C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(1338): Mage_Cron_Model_Observer->dispatch(Object(Varien_Event_Observer))
#3 C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Cron_Model_Observer), ''dispatch'', Object(Varien_Event_Observer))
#4 C:\xampp\htdocs\magento\app\Mage.php(448): Mage_Core_Model_App->dispatchEvent(''default'', Array)
#5 C:\xampp\htdocs\magento\cron.php(74): Mage::dispatchEvent(''default'')
#6 {main}'

full config.xml

<config>
    <modules>
        <mycompany_mymodule>
            <version>1.0.0</version>
        </mycompany_mymodule>
    </modules>

    <global>
        <models>
            <Mymodule>
                <class>Mycompany_Mymodule_Model_Observer</class>
            </Mymodule>
        </models>
    </global>

    <crontab>
        <jobs>
            <mycompany_mymodule>
                <schedule>
                    <cron_expr>* * * * *</cron_expr>
                </schedule>
                <run>
                    <model>mymodule/model_cron::editEntries</model>
                </run>
            </mycompany_mymodule>
        </jobs>
    </crontab>
</config>

----- ediit -----

so the cron attribute should look like this?

<crontab>
    <jobs>
        <mycompany_mymodule>
            <schedule>
                <cron_expr>* * * * *</cron_expr>
            </schedule>
            <run>
                <model>mycompany_mymodule_model/observer::editEntries</model>
            </run>
        </mycompany_mymodule>
    </jobs>
</crontab>

1 Answer 1

4

You have missing model and you need to define models Just add models to config.xml

<global>
    <models>
        <mymodule>
            <class>Mycompany_Mymodule_Model</class>
        </mymodule>
    </models>
</global>

And Observer.php localation is app/code/yourmodulecodepool/Mycompany/Mymodule/Model

Edit:

Issue1:

as you have set mymodule/observer .That mean mymodule/observer

mymodule is a model class prefix which in config.xml

your code is model prefix and always be in lower letter

<global>
        <models>
            <mymodule> <!--  change <Mymodule> to <mymodule>  -->
                 <class>Mycompany_Mymodule_Model</class>
            </mymodule> <!-- same chnage here -->
        </models>
    </global>

Issue2:

mymodule/model_cron is run as model which in run on cron job

magento is manupulate this it class by

mymodule= Mycompany_Mymodule_Model as i define at config xml

model_cron =Model_Cron

the final class is Mycompany_Mymodule_Model_Model_Cron it path should be

app/code/yourmodulecodepool/Mycompany/Mymodule/Model/Model/Cron.php

If you use mymodule/model_cron::editEntries in cron then this file path location

 app/code/yourmodulecodepool/Mycompany/Mymodule/Model/Observer.php

and class is

 Mycompany_Mymodule_Model_Observer

Modified config.xml

<?xml version="1.0" ?>
<config>
    <modules>
        <Mycompany_Mymodule> <!-- module should be same sa filepath -->
            <version>1.0.0</version>
        </Mycompany_Mymodule>
    </modules>

   <global>
        <models>
            <mymodule> <!--  change <Mymodule> to <mymodule>  -->
                 <class>Mycompany_Mymodule_Model</class>
            </mymodule> <!-- same chnage here -->
        </models>
    </global>

    <crontab>
        <jobs>
            <mycompany_mymodule>
                <schedule>
                    <cron_expr>* * * * *</cron_expr>
                </schedule>
                <run>
                    <model>mymodule/observer::editEntries</model>
                </run>
            </mycompany_mymodule>
        </jobs>
    </crontab>
</config>
7
  • what do you mean with "Observer is model class an it is not observer" ? thanks for helping Sep 26, 2014 at 18:17
  • Mycompany_Mymodule_Model_Observer is model class which is used as observer.It location should in modelfolder
    – Amit Bera
    Sep 26, 2014 at 18:21
  • i have set my model but i am using this tag <class><Mycompany_Mymodule_Model_Observer</class>. isn't correct that way ? Sep 26, 2014 at 18:24
  • please full config.xml.thus i can check
    – Amit Bera
    Sep 26, 2014 at 18:27
  • so how the crontab attribute should look like in config.xml ? is there any way to check where magento is expecting to find the model used for the cronjob ? Sep 26, 2014 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.