0

Am having problems running tasks when setup as class methods. I've read about celery.contrib.methods from the answer here on SO but am not able to apply it to my case.

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()

With the above configuration, I keep getting the errors [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'>

How should I configure or import items in order for it to work?

celery_version = 3.1.16 python_version = python3.4

Community
  • 1
  • 1
lukik
  • 3,919
  • 6
  • 46
  • 89
  • You are serializing "self", and it can't be decoded. Why would like to include worker task in your model class? – ant31 Oct 31 '14 at 19:43
  • The model class is in a package that just processes data from files about students. It grabs student IDs and does a bunch a data cleaning. That said, as per the links provided in the question, it seems possible to run tasks using class methods. I understand self can't be serialized but then if I omit it it throws an error about missing self. Assuming my use case made sense, please guide on how I'd make the declarations or how I'd call the task. Thanks. – lukik Nov 01 '14 at 02:25

0 Answers0