我正在尝试用完美的流程包装一个类,该流程目前通过看起来像这样的类来工作:
class Algorightm:
@task
def do_first(self, something):
....
@task
def do_second(self, something_else):
....
@flow
def start_flow(self):
do_first(..)
do_second(..)
通常情况下,这可以正常工作,如果我将其分解为外部函数,则流程可以正常运行,这意味着如果我只是在类之外使用它,则可以根据需要工作:
这会起作用:
@task
def do_first(self, something):
....
@task
def do_second(self, something_else):
....
@flow
def start_flow(self):
do_first(..)
do_second(..)
但是当在类中使用它时,它会给我一个递归错误。 问题是,prefect是否支持在类中使用It's flow?我在文档中找不到任何有关它的信息
最佳答案
Prefect 流程必须是函数而不是类方法。否则,您将无法为其创建部署。但是,您可以在该函数中调用您的类,Prefect 甚至支持使用 Pydantic 进行参数验证(如果您使用此类来获取 pydantic 模型样式验证,则共享此 pydantic 信息)
关于python - 在Python中的数据类上使用prefect 2.0流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74168859/