In Celery, up to version 4, there was experimental support for declaring class methods as tasks, and now it has been removed.

I am currently working with one old repository with GitHub, in which exactly the class method was the Celery task and actively used self links inside itself, i.e. It can not be displayed in a static method.

How is this problem now solved in Celery 4, when is it necessary to make a method using a Celery task?

  • one
    Most likely you will have to write a new class for the task with the run method, and you can transfer a serialized object and work with it, or do a deeper refactoring all the same - Barton
  • @Barton, that is, now you need to write a custom task in Celery 4, inheriting it from Task , right? - Dmitry Zharkov
  • yes, or use decorator celery.readthedocs.io/en/latest/reference/... which under the cut anyway creates an instance of the class. - Barton

0