当我尝试将任务传递给Celery工作者时,我收到此错误。这是追溯
Traceback:
File "/home/vivek/xpython/lib/python2.6/site-packages/Django-1.3-py2.6.egg/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/vivek/projects/engine/engine/web/models.py" in fb_sync
53. process_metadata.delay(self, wrapper)
File "/home/vivek/xpython/lib/python2.6/site-packages/celery-2.2.7-py2.6.egg/celery/task/base.py" in delay
338. return self.apply_async(args, kwargs)
File "/home/vivek/xpython/lib/python2.6/site-packages/celery-2.2.7-py2.6.egg/celery/task/base.py" in apply_async
460. **options)
File "/home/vivek/xpython/lib/python2.6/site-packages/celery-2.2.7-py2.6.egg/celery/app/amqp.py" in delay_task
230. send(body, exchange=exchange, **extract_msg_options(kwargs))
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/compat.py" in send
101. return self.publish(*args, **kwargs)
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/messaging.py" in publish
124. compression, headers)
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/messaging.py" in _prepare
147. body) = encode(body, serializer=serializer)
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/serialization.py" in encode
119. payload = encoder(data)
File "/home/vivek/xpython/lib/python2.6/copy_reg.py" in _reduce_ex
84. dict = getstate()
Exception Type: TypeError at /login/
Exception Value: 'str' object is not callable
/home/vivek/xpython/lib/python2.6/copy_reg.py in _reduce_ex
dict = getstate() ...
local variables
{'args': (<web.models.User object at 0x8b47b4c>,<web.fb.Facebook object at 0x8b4fbac>),
'eta': None,
'expires': None,
'id': '8d8e6c0b-a269-4780-9c48-77e689037322',
'kwargs': {},
'retries': 0,
'task': 'web.models.process_likes'}
What is the solution to this problem? When I remove the task decorator, it works fine.
答案 0 :(得分:2)
您正在尝试将对象传递给无法序列化的任务。尝试传递更简单的数据(让您在运行任务时重新创建复杂对象的信息)。
不确定这是否是您的错误的实际原因,但您不应该将Django模型传递给任务。否则你将遇到竞争条件。请参阅主题的Celery documentation:
不应将它们作为任务的参数传递。在任务运行时,从数据库重新获取对象几乎总是更好,因为使用旧数据可能会导致竞争条件。
将用户对象的唯一键和您需要的任何内容传递为简单的python类型来识别Facebook Like交互,并使用任务中的信息来重新创建执行任务所需的内容。