Elliot Løvås
01/12/2023, 5:36 PMNate
01/12/2023, 8:58 PMWhile you can build your task logic within a class, we recommend defining tasks as functions. Since the flow’s computational graph is discovered at runtime, there is no need for a rigid class-based task definition.
Classes are stateful, while tasks are executed in a stateless manner to support concurrency and distributed parallelism. Additionally, splitting the orchestration framework into two APIs confuses many users.
If you need to define some logic in classes, you can still either:
• call them in your functional tasks,
• initialize and invoke class methods directly in your flow.We don't have examples of this because its not a pattern we generally recommend. If you'd like to describe your use case, I'd be happy to give my 2 cents on how you might achieve it with prefect using a functional approach
Elliot Løvås
01/17/2023, 12:46 PMNate
01/17/2023, 10:33 PMTask
. The way I think about it is, I want the prefect engine to manage the state of things for me, I don't want to assume that responsibility by potentially changing the nature of a task / how they communicate their state to the API.
that said, there's nothing stopping you from doing so, in my head it just opens the door for unexpected behavior
some other patterns I'd recommend if you just want to customize how certain tasks work
• you can inject functionality into tasks without changing how the base prefect task works by using additional decorators (like this, or this)
• you can define your own class independently of Task
and use it within task decorated functions as desired
• you can dynamically configure existing tasks by using .with_options