https://prefect.io logo
Title
j

Jackson Maxfield Brown

02/03/2020, 10:20 PM
Question: is it possible to use the @task decorator on a class method?
c

Chris White

02/03/2020, 10:24 PM
I don’t believe so, as Prefect will probably complain that
self
is a missing argument
j

Jackson Maxfield Brown

02/03/2020, 10:24 PM
Yep. That is what we are running into
Any ideas for a work around? Besides writing a function that inits the class, runs the function, and returns?
c

Chris White

02/03/2020, 10:29 PM
I’d recommend subclassing your custom class as a Task:
class MyPrefectClass(MyCustomClass, Task):
    ...
    def run(self, *args, **kwags):
        # same logic as the method you wanted to decorate
that way all of your statefulness that you are relying on the class for is tracked on the
Task
object