Hi everyone, I am new to prefect, so maybe my question seems naive! is it possible to use @task for methods inside a class? I have a class with several methods that can be set as task.
z
Zach Angell
09/02/2021, 1:36 PM
Hi @Alireza Taghizadeh, the @task decorator is not meant to work with methods in classes. If the methods are
staticmethods
, it may work in some cases.
The simplest workaround (assuming your class is not keeping meaningful state) would be to have a simple functional task that instantiates your class and calls the relevant method
Tnx Zach, that is indeed, what I have done (even though my methods are not static, I made a similar hack to make them used as a function and use @task), but I thought maybe a more elegant way exists. Anyway, thanks a lot for your help.
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.