AOEpeople / Aoe_Scheduler

Cron Scheduler Module for Magento
http://fbrnc.net/blog/2011/03/magento-cron-schedule
GNU General Public License v3.0
373 stars 202 forks source link

Cron Invalid Callback for catalog/observer::reindexProductPrices #177

Closed gbillingsley closed 9 years ago

gbillingsley commented 9 years ago

I'm getting the following exception every time catalog/observer::reindexProductPrices runs (once a day). I believe this is a standard Magento cron job, and the configuration and function look normal as well, so I'm not sure what the problem is. I'm running Magento 1.14.2.0 and AOE Scheduler 1.2.1.

---EXCEPTION--- exception 'Mage_Core_Exception' with message 'Invalid callback: catalog/observer::reindexProductPrices does not exist' in /var/magento/magento-1-14-2-0/releases/20150928182542/app/Mage.php:595 Stack trace:

0 /var/magento/magento-1-14-2-0/releases/20150928182542/app/code/community/Aoe/Scheduler/Helper/Data.php(298): Mage::throwException('Invalid callbac...')

1 /var/magento/magento-1-14-2-0/releases/20150928182542/app/code/community/Aoe/Scheduler/Model/Job.php(143): Aoe_Scheduler_Helper_Data->getCallBack('catalog/observe...')

2 /var/magento/magento-1-14-2-0/releases/20150928182542/app/code/community/Aoe/Scheduler/Model/Schedule.php(189): Aoe_Scheduler_Model_Job->getCallback()

3 /var/magento/magento-1-14-2-0/releases/20150928182542/app/code/community/Aoe/Scheduler/Model/Schedule.php(579): Aoe_Scheduler_Model_Schedule->runNow(true)

4 /var/magento/magento-1-14-2-0/releases/20150928182542/app/code/community/Aoe/Scheduler/Model/Observer.php(39): Aoe_Scheduler_Model_Schedule->process()

5 /var/magento/magento-1-14-2-0/releases/20150928182542/app/code/core/Mage/Core/Model/App.php(1338): Aoe_Scheduler_Model_Observer->dispatch(Object(Varien_Event_Observer))

6 /var/magento/magento-1-14-2-0/releases/20150928182542/app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Aoe_Scheduler_Model_Observer), 'dispatch', Object(Varien_Event_Observer))

7 /var/magento/magento-1-14-2-0/releases/20150928182542/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('default', Array)

8 /var/magento/magento-1-14-2-0/releases/20150928182542/shell/scheduler.php(367): Mage::dispatchEvent('default', Array)

9 /var/magento/magento-1-14-2-0/releases/20150928182542/shell/scheduler.php(30): Aoe_Scheduler_Shell_Scheduler->cronAction()

10 /var/magento/magento-1-14-2-0/releases/20150928182542/shell/scheduler.php(393): Aoe_Scheduler_Shell_Scheduler->run()

11 {main}

Here is the related section of the config.xml (app/code/core/Mage/Catalog/etc/config.xml):

<crontab>
    <jobs>
        <catalog_product_index_price_reindex_all>
            <schedule>
                <cron_expr>0 2 * * *</cron_expr>
            </schedule>
            <run>
                <model>catalog/observer::reindexProductPrices</model>
            </run>
        </catalog_product_index_price_reindex_all>
    </jobs>
</crontab>

And here is the function (app/code/core/Mage/Catalog/Model/Observer.php):

/**
 * Cron job method for product prices to reindex
 *
 * @param Mage_Cron_Model_Schedule $schedule
 */
public function reindexProductPrices(Mage_Cron_Model_Schedule $schedule)
{
    $indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price');
    if ($indexProcess) {
        $indexProcess->reindexAll();
    }
}

Thanks.

LeeSaferite commented 9 years ago

Can you try using the code on the master branch? I modified the code to be a bit more informative about why the callback is invalid. That will help diagnose situations like yours a bit easier.

LeeSaferite commented 9 years ago

If you just want to patch your code, look here for the change: https://github.com/AOEpeople/Aoe_Scheduler/commit/7d26ab196fb322d3408065599aa282deea2396d2

gbillingsley commented 9 years ago

After patching the code, I tried to change the cron time to test it out (Scheduler -> Job Configuration). When trying to save the cron job, I received this error: "Invalid callback: Method for catalog/observer::reindexProductPrices does not exist".

LeeSaferite commented 9 years ago

So, that's telling you the loaded class doesn't have that method. Which seems odd considering the class you are expecting to load does contain the method.

gbillingsley commented 9 years ago

Right, it's odd. Is it possible it's overridden somewhere?

LeeSaferite commented 9 years ago

That would be my guess. You could log the actually loaded class at the point the exception is throw with a call to get_class()

gbillingsley commented 9 years ago

Thanks, that helped track it down. We have a custom observer, let's call it X_Catalog_Model_Observer, that is getting loaded instead of the base one. The strange thing is that X_Catalog_Model_Observer extends Enterprise_Catalog_Model_Observer, not Mage_Catalog_Model_Observer, and Enterprise_Catalog_Model_Observer is completely different from Mage_Catalog_Model_Observer.

So, my question is, why is the cron job loading X_Catalog_Model_Observer instead of Mage_Catalog_Model_Observer for reindexProductPrices?

Here is the relevant config.xml for the custom observer:

<crontab>
<events>
  <sitemap_categories_generating_before>
    <observers>
      <set_category_url_suffix>
        <class>X_Catalog_Model_Observer</class>
        <method>addSeoSuffixToCategoryUrl</method>
      </set_category_url_suffix>
    </observers>
  </sitemap_categories_generating_before>
  <sitemap_products_generating_before>
    <observers>
      <set_product_url_suffix>
        <class>X_Catalog_Model_Observer</class>
        <method>addSeoSuffixToProductUrl</method>
      </set_product_url_suffix>
    </observers>
  </sitemap_products_generating_before>
</events>
</crontab>

And here's the file:

<?php
class X_Catalog_Model_Observer extends Enterprise_Catalog_Model_Observer
{
/**
 * Add Seo suffix to category's URL if doesn't exists.
 *
 * @param Varien_Event_Observer $observer
 */
public function addSeoSuffixToCategoryUrl(Varien_Event_Observer $observer)
{
  # CUSTOM - Removing function content because it adds a '.' to the end of the URL
}

/**
 * Add Seo suffix to product's URL if doesn't exists.
 *
 * @param Varien_Event_Observer $observer
 */
public function addSeoSuffixToProductUrl(Varien_Event_Observer $observer)
{
  # CUSTOM - Removing function content because it adds a '.' to the end of the URL
}
}
gbillingsley commented 9 years ago

Ok, after some investigation, I figured out the problem. The custom module was overriding the "catalog" observer instead of the "enterprise_catalog" observer. Thanks for your help in tracking down the issue.

abhishek-sinha commented 8 years ago

Hi,

I am facing issue

exception 'Mage_Core_Exception' with message 'Invalid callback: Model for feed/generator::checkRecreateImages does not exist'

i am using AOE Scheduler extension for cron

Please help me what exactly issue with this