2

I have installed a magento module called Mage-Resque using composer. Composer has installed all the components into a directory called Vendor. When I run the module, one of the component needs to access the class Mns_Resque_Model_Job_Logmessage. But it always returns error Class not found.

As per my understanding the codes in Vendor directory cannot access the Namespace of Magento. How can I solve this issue should I something additional config in composor.json file.

EDIT

Here is the error message that I get

Could not find job class Mns_Resque_Model_Job_Logmessage
backtrace : vendor/chrisboulton/php-resque/lib/Resque/Job.php(172): Resque_Job_Factory->create('Mns_Resque_Mode...', Array, 'default')\",\"#1 //vendor/chrisboulton/php-resque/lib/Resque/Job.php(189): Resque_Job->getInstance()\",\"#2 //vendor/chrisboulton/php-resque/lib/Resque/Worker.php(240): Resque_Job->perform()\",\"#3 //vendor/chrisboulton/php-resque/lib/Resque/Worker.php(202): Resque_Worker->perform(Object(Resque_Job))\",\"#4 //vendor/chrisboulton/php-resque/bin/resque(127): Resque_Worker->work(5, false)

EDIT

When I searched I found that the check ie the check for to whether class exists happens in following path vendor/chrisboulton/php-resque/lib/Resque/Job/Factory.php. But the model class is in app/code/community/Mns/Resque/Model/Job/Logmessage.php.

Composer.json

{

    "require": {
        "ajbonner/mage-resque": "*",
        "magento-hackathon/magento-composer-installer": "*"
    },
    "require-dev": {
        "aoepeople/aoe_profiler": "*",
        "magetest/magento-phpunit-extension": "*"
    },
    "repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/magento-hackathon/magento-composer-installer"
    },
    {
        "type": "vcs",
        "url": "https://github.com/ajbonner/magento-composer-autoload"
    },
    {
        "type": "vcs",
        "url": "https://github.com/ajbonner/mage-resque"
    },
    {
        "type": "vcs",
        "url": "https://github.com/MageTest/Mage-Test"
    },
    {
        "type": "vcs",
        "url": "https://github.com/fbrnc/Aoe_Profiler"
    }
    ],
    "extra":{
        "magento-root-dir": "./",
        "magento-deploystrategy":"copy" 
    },
    "config": {
        "bin-dir": "shell"
    }
    "minimum-stability": "dev"
}

To test I have created a controller action from which I'm queuing a job. The job seems to be getting queued in Redis server but then it results in above error.

Here is the code in controller action I'm using (Please note that this is code I copied from GitHub page for Mage Resque)

$resque = Mage::getSingleton('mnsresque/factory')->create();
$resque->addJob(
    'Mns_Resque_Model_Job_Logmessage',
    array('message'=>'foo'));

As per the error log the error occurs in the following file

vendor/chrisboulton/php-resque/lib/Resque/Job/Factory.php:16

Which is outside of the Magento app/ folder structure. And following is the code that causes this error.

if (!class_exists($className)) {
            throw new Resque_Exception(
                'Could not find job class ' . $className . '.'
            );
        }

The class above code trying to access is defined in app/code/local/community/Mns/Resque/Model/Job/. I have also tried copying the entire folder Mns to /chrisboulton/php-resque/lib/Resque/Job/ thinking that the class_exists checks in the current folder. But that too is not working.

How I can resolve this issue. Have i missed something?

  • Are you sure it's Magento 1.9? – Adarsh Khatri Dec 18 '16 at 22:20
  • Yes... When i searched i found that the check ie the check for to whether class exists happens in following path vendor/chrisboulton/php-resque/lib/Resque/Job/Factory.php. But the model class is in app/code/community/Mns/Resque/Model/Job/Logmessage.php. – nikhil Dec 19 '16 at 4:32
  • "As per my understanding the codes in Vendor directory cannot access the Namespace of Magento" - No. Or does the module run some scripts outside the context of Magento? Then you would need to initialize the Varien_Autoload autoloader, because the composer autoloader does not load classes from Magento modules. Can you share your code? Another possibility is that Mns_Resque_Model_Job_Logmessage cannot be found because the file is not readable. – Fabian Schmengler Dec 19 '16 at 14:16
  • Hi i have edited the question and added some codes. Please let me know if that is enough. – nikhil Dec 21 '16 at 5:06
3
+25

This has to work, the issue is not in the code.

Possible reasons:

  • app/code/community/Msn/Resque/Model/Job/Logmessage.php is not readable. Please double check permissions and owner.
  • Opcode cache (like APC) is in place and not up to date. Flush it.
  • You use the Magento compiler. Recompile, or better, disable it entirely.

Explanation why you are looking in the wrong direction:

  1. The code is called from a Magento controller, and Mage::getSingleton('mnsresque/factory') did not result in an error, from that I conclude:

    • the Magento autoloader works
    • the module files are in the right location
  2. You get an error in vendor/chrisboulton/php-resque/lib/Resque/Job/Factory.php, that means:

    • the 3rd party library in vendor can be loaded as well
  • I have checked the permissions and confirmed that the folder has 777.Compiler is disabled by default and there is no cache. – nikhil Dec 21 '16 at 10:28
  • Resque is symlinked to Vendor folder – nikhil Dec 21 '16 at 10:31
  • Are you sure that's the case @nikhil? "magento-deploystrategy":"copy" should prevent it from symlinking, which is the default behavior, and might have some cleanup tasks that aren't expected behavior. It likely won't solve the problem but, have to attempted to install the plugin without that line? – Jonathan Wommack Dec 28 '16 at 0:32

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.