Note that there are some explanatory texts on larger screens.

plurals
  1. POinvoke celery task from tornado
    primarykey
    data
    text
    <p>How can someone invoke a celery task from tornado, and get the result via a callback? </p> <p>This <a href="http://www.toforge.com/2011/01/run-celery-tasks-from-php/" rel="nofollow">post</a> claims that someone must simply put a message via RabbitMQ and then the task shall be executed. This makes sense, but can someone give an example in python (even better in tornado, with a callback)? Personally, I use mongodb as my message broker, but I can switch to Redis or RabbitMQ as well..</p> <p>EDIT: To clarify things, I want an example with a callback. For example, this tornado code</p> <pre><code>TestTask.delay(callback = self._on_celery_response) ... def _on_celery_response(self, result): print "hello from _on_celery_repsonse" , result </code></pre> <p>does not work. My TestTask is:</p> <pre><code>class TestTask(Task): name = "tornadoServer.Test" def run(self, callback=None, **kwargs): result = {'result': "hello from celery task invoked by tornado"} if callback is not None: subtask(callback).delay(result) return result </code></pre> <p>and the traceback:</p> <pre><code> File "/home/hymloth/Desktop/DJANGO/NOO1/tornadoServer/tornado/stack_context.py", line 183, in wrapped callback(*args, **kwargs) File "/home/hymloth/Desktop/DJANGO/NOO1/tornadoServer/asyncmongo/connection.py", line 183, in _parse_response callback(response) File "/home/hymloth/Desktop/DJANGO/NOO1/tornadoServer/asyncmongo/cursor.py", line 399, in _handle_response orig_callback(result['data'], error=None) File "/home/hymloth/Desktop/DJANGO/NOO1/tornadoServer/basic_auth_handlers.py", line 66, in _on_response celery_tasks.TestTask.delay(self._on_celery_response) File "/usr/local/lib/python2.6/dist-packages/celery-2.2.7-py2.6.egg/celery/task/base.py", line 338, in delay return self.apply_async(args, kwargs) File "/usr/local/lib/python2.6/dist-packages/celery-2.2.7-py2.6.egg/celery/task/base.py", line 460, in apply_async **options) File "/usr/local/lib/python2.6/dist-packages/celery-2.2.7-py2.6.egg/celery/app/amqp.py", line 230, in delay_task send(body, exchange=exchange, **extract_msg_options(kwargs)) File "/usr/local/lib/python2.6/dist-packages/kombu-1.1.6-py2.6.egg/kombu/compat.py", line 101, in send return self.publish(*args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/kombu-1.1.6-py2.6.egg/kombu/messaging.py", line 124, in publish compression, headers) File "/usr/local/lib/python2.6/dist-packages/kombu-1.1.6-py2.6.egg/kombu/messaging.py", line 147, in _prepare body) = encode(body, serializer=serializer) File "/usr/local/lib/python2.6/dist-packages/kombu-1.1.6-py2.6.egg/kombu/serialization.py", line 119, in encode payload = encoder(data) File "/usr/lib/python2.6/copy_reg.py", line 70, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle instancemethod objects </code></pre> <p>The Task works ok without the callback.. Any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload