1

I am trying to get celery tasks wrapper around a python object method. Like:

 class A:
      @task
      def test_task(self,args):
        print "BLah..test"

   def main():
     a= A()
     args = {}
     a.test_task(args)

Now this fails with error test_task takes atleast 2 arguments (1 given). My understanding is the self object is not getting passed. Why is this so? and how do i work around this?

Update: It really was my lack of understanding of celery. the @task decorator is just to add/handle the celery task related parameters. it doesn't automatically make every call to the function a celery task. the function must be called as a.test_task.delay(args).. therein the problem...

2 Answers2

4

Since version 3.0 Celery now supports using methods as tasks: http://docs.celeryproject.org/en/latest/reference/celery.contrib.methods.html

asksol
  • 17,700
  • 5
  • 55
  • 65
  • 2
    Not anymore since 2014-10-10. Apparently it was too buggy. https://github.com/celery/celery/commit/4f43276c236bbef7239a49b93815f478aec1d9f6 – mikenerone Dec 16 '14 at 09:19
0

Do you need to have test_task as method? Will simple function work? Or could you use static method? BTW, your main function doesn't use celery to execute test_task, it runs it as simple method.

demalexx
  • 4,255
  • 1
  • 27
  • 34