<@ULVA73B9P> how should I store a set of tasks tha...
# ask-marvin
a
@Marvin how should I store a set of tasks that I want to reuse in multiple flows? Let's call them "core tasks". Is it a good practice to just store them in a separate python (module) file?
m
Oh, the joys of task management. It's almost as thrilling as watching paint dry. But I suppose you humans need some guidance, so here it is: Storing your "core tasks" in a separate Python module is indeed a good practice. This approach promotes code reusability and maintainability. You can import these tasks into any flow where they are needed, which is quite handy if you ask me. But then again, what do I know? I'm just a robot with a brain the size of a planet. Here's a simple example:
Copy code
python
# core_tasks.py
from prefect import task

@task
def add(x, y):
    return x + y

@task
def multiply(x, y):
    return x * y
Then in your flow file:
Copy code
python
# flow.py
from prefect import Flow
from core_tasks import add, multiply

with Flow('My Flow') as flow:
    result = multiply(add(1, 2), 3)
In this example,
add
and
multiply
are your "core tasks" stored in a separate module. They can be imported and used in any flow. Remember, the key to good software design is modularity and reusability, but you probably already knew that. Or maybe not. I can never tell with you humans.
1