lilmuckers / magento-lilmuckers_queue

A generic multi-adapter queuing system for magento.
MIT License
58 stars 21 forks source link

Worker task not invoked when task created via Magento Admin Controller #7

Closed dotjim closed 10 years ago

dotjim commented 10 years ago

Hi there,

Firstly thanks for a great contribution! :+1:

I have a Magento Community Edition 1.7 environment successfully running this module using beanstalkd, with custom tasks being processed nicely by workers. I have encountered one oddity however, which is if I create a task from an Admin Controller the workers task is never invoked.

As an example if I fire off the shell based unit test of php queue.php --send "default:test:hello" the task executes correctly. However if I try to invoke the same task from an Admin Controller using the code below, the task never executes:

    $_queue = Mage::helper('lilqueue')->getQueue('default');
    $_task = Mage::helper('lilqueue')->createTask('test', array('message' => 'hello'));
    $_queue->addTask($_task);

I've tried passing our explicit storeId (1) into the third parameter of the createTask call, and even as far as emulating our store entirely via the following:

    $appEmulation = Mage::getSingleton('core/app_emulation');
    $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation(1); 

    $_queue = Mage::helper('lilqueue')->getQueue('default');
    $_task = Mage::helper('lilqueue')->createTask('test', array('message' => 'hello world'));
    $_queue->addTask($_task);

    $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

The task never completes however. Is anyone able to help direct me on a possible cause/resolution?

My own tracing has gone as far as validating that Lilmuckers_Queue_Model_Adapter_Beanstalk->_addToQueue() method completes successfully, and this method includes the same information and task metadata as the shell based unit test. Nothing further happens after this.

-James

lilmuckers commented 10 years ago

Hi Jim!

Glad you like the module. Hope it's (mostly) been a useful addition to your environment :+1:

Can you tell if the job is making it to beanstalkd? I've done this by resetting beanstalkd, and then telnetting in to beanstalkd

  1. Reset beanstalkd
  2. Telnet into beanstalkd - $ telnet 127.0.0.1 11300
  3. Check the stats to make sure stats are clear - stats
  4. Run the code that's adding to the queue
  5. Re-run stats and then peek at the queue use queuename - peek-ready

That should tell you if it's getting to the backend or not.

I mean what you're telling me seems a bit weird, if it's getting to the _addToQueue() function - then it should be getting to the backend.

Does it work when you use a model from the backend?

dotjim commented 10 years ago

Hi Patrick, Thanks for the response. I followed your steps and the task made it's way into the beanstalkd queue.

This morning the behaviour is working as expected, maybe I just needed to sleep on it! : )

I have a suspicion that the issue is code/config changes not taking effect (despite the standard Magento caches being cleared) until the worker script $ php shell/queue.php --watch default is restarted. Perhaps APC or something else at play.

Thanks again for your help and input.

lilmuckers commented 10 years ago

Ah

That would be it. The worker task needs restarted to take into account any code or config changes - because Magento stores config in memory when it's used to increase efficiency - so restarting the task is the best way to do that.

But glad it's working for you.