11

I have a class with methods decorate with celery @task like this:

class Port(object): 

    """docstring for Port"""


    def __init__(self,):
        print 'Class has been initialized ...'


    @celery.task(filter=task_method,name="Port.process")    
    def process(self,):
        print "I'm inside the process task method: " 

Called here:

p = Port()

p.process.apply_async()

I also tried: p.process.delay(), with the same below result.

When I run it, I get this error:

[2013-06-22 02:32:53,988: ERROR/MainProcess] Task Port.process[77cff07e-4bc5-4e36-9c4e-b68d7616c74e] raised exception: TypeError('process() takes at least 1 argument (0 given)',) Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/celery/task/trace.py", line 228, in trace_task R = retval = fun(*args, **kwargs) File "/usr/local/lib/python2.7/site-packages/celery/task/trace.py", line 415, in __protected_call__ return self.run(*args, **kwargs) TypeError: process() takes at least 1 argument (0 given)

This is the important part, TypeError: process() takes at least 1 argument (0 given).

Now how can I solve this??

Some people say this happens because celery uses the method task unbound to the initialized object, and some others say it just works, do I miss something here?

securecurve
  • 5,589
  • 5
  • 45
  • 80
  • If by "class methods" you mean normal instance methods (as your example implies), this is probably a duplicate of [using class methods as celery tasks](http://stackoverflow.com/questions/9250317/using-class-methods-as-celery-tasks). If you already knew about that, but you're actually talking about `@classmethod`s here, please clarify and given an appropriate example. – abarnert Jun 21 '13 at 23:58
  • Regarding your question ... Yes, I mean instance methods. Regarding the link you provided, I already followed it, now I get the above error ... – securecurve Jun 22 '13 at 00:07
  • Does this answer your question? [using class methods as celery tasks](https://stackoverflow.com/questions/9250317/using-class-methods-as-celery-tasks) – Huseyin Yagli Apr 09 '20 at 15:35

1 Answers1

3

Celery has experimental support for using methods as tasks since version 3.0.

The documentation for this is in celery.contrib.methods, and also mentions some caveats you should be aware of:

http://docs.celeryproject.org/en/latest/reference/celery.contrib.methods.html

Used this as reference

Community
  • 1
  • 1
securecurve
  • 5,589
  • 5
  • 45
  • 80
  • 5
    This appears to have been removed recently as it was too buggy - https://github.com/celery/celery/commit/4f43276c236bbef7239a49b93815f478aec1d9f6 – Hamy Apr 04 '15 at 06:49