D
D
Dmitry2018-02-27 20:38:00
Python
Dmitry, 2018-02-27 20:38:00

How to make a class method a Celery task?

I'm digging through one abandoned repository on GitHub, and there the class method is used as a task in Celery,
i.e.

class SomeClass(object):

    def __init__(self, celery):
        self.task = celery.task(self.task_method)

    def task_method(self, param1, param2):
        return param1 + param2

    def _logic(self):
        foo = self.task.s(param1, param2)
        return foo.apply_async()

Well, in the last line, a `ValueError` crashes with a cry that `task_method` takes 3 arguments, and only 2 are passed!
In Celery 3, there was test support for decorators for methods, and in the 4th it was removed, and now it’s not at all clear to me how to make a task in Celery from a class method :(

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question