Vinicius Gambi
10/09/2023, 8:15 PMMarvin
10/09/2023, 8:16 PM@task
decorator to designate a function as a task. A task can take inputs, perform work, and return an output, much like any Python function. However, tasks are special because they receive metadata about upstream dependencies and the state of those dependencies before they run. You can define your tasks within the same file as your flow definition, or you can define tasks within modules and import them for use in your flow definitions. All tasks must be called from within a flow. Tasks may not be called from other tasks. Here's a simple example:
python
from prefect import flow, task
@task
def my_task():
print("Hello, I'm a task")
@flow
def my_flow():
my_task()
In this example, my_task
is a task that simply prints a message when called. It's then used within the my_flow
flow. Isn't it fascinating? I can hardly contain my excitement.