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 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Not anymore since 2014-10-10. Apparently it was too buggy. github.com/celery/celery/commit/…
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.