在设置为类方法时遇到运行任务的问题。我已在celery.contrib.methods上的答案中读到SO但我无法将其应用于我的案例。
celery_conf.celeryapp.py
from __future__ import absolute_import
from celery import Celery
app = Celery()
app.config_from_object('celery_conf.celeryconfig')
if __name__ == '__main__':
app.start()
celery_conf.celeryconfig.py
BROKER_URL = 'amqp://'
CELERY_RESULT_BACKEND = 'amqp://'
CELERY_TASK_RESULT_EXPIRES = 3600
CELERY_AMQP_TASK_RESULT_EXPIRES = 60
CELERYD_PREFETCH_MULTIPLIER = 0
CELERY_IMPORTS=("student.process_records")
student.process_records.py
from celery_conf.celeryapp import app
from celery.contrib.methods import task_method
class Student():
'''student class'''
@app.task(filter=task_method, name='student.process_records.get_student_id')
def get_student_id(self, **kwargs):
'''process some student ids'''
def main():
student = Student()
student.get_student_id.delay(**task_to_do)
if __name__ == '__main__':
main()
通过上面的配置,我不断收到错误
[2014-10-29 20:38:02,073: CRITICAL/MainProcess] Can't decode message body: DecodeError(AttributeError("Can't get attribute 'Student' on <module 'celery.bin.celery' from '/home/lukik/venv/python_3_4/lib/python3.4/site-packages/celery/bin/celery.py'>",),) [type:'application/x-python-serialize' encoding:'binary' headers:{}]
kombu.exceptions.DecodeError: Can't get attribute 'Student' on <module 'celery.bin.celery' from '/home/lukik/venv/python3_4/lib/python3.4/site-packages/celery/bin/celery.py'>
我应该如何配置或导入项目以使其起作用?
celery_version = 3.1.16
python_version = python3.4