Software Mechanic
Software Mechanic

Reputation: 994

celery python object methods

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...

Upvotes: 1

Views: 2392

Answers (2)

asksol
asksol

Reputation: 19479

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

Upvotes: 4

demalexx
demalexx

Reputation: 4761

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.

Upvotes: 0

Related Questions