Colton
04/17/2024, 3:56 PMMarvin
04/17/2024, 3:56 PMSequentialTaskRunner
can enforce tasks to run sequentially. Additionally, you can manually define upstream dependencies to ensure a task waits for another to complete before running.
You can set the task dependency using the wait_for
argument:
python
from prefect import flow, task
@task
def upstream():
# your upstream task logic
@task
def downstream(wait_for):
# your downstream task logic
@flow
def flow_of_tasks():
upstream_result = upstream.submit()
downstream_result = downstream.submit(wait_for=[upstream_result])
return downstream_result
If you have separate Python scripts that you want to run in sequence within a Prefect flow, you can wrap the script execution within tasks and use similar wait_for
logic to sequence them.
You can find more details about running tasks sequentially in the Task Runners documentation and about specifying upstream dependencies in the Specifying Upstream Dependencies guide.Kevin Grismore
04/17/2024, 3:57 PMColton
04/17/2024, 3:58 PMKevin Grismore
04/17/2024, 3:59 PM@flow
and call them both in sequence from within a flow, and they'll both show up as fully fledged flows in the UIColton
04/17/2024, 4:01 PM@flow
def mainflow():
scriptflow1_result = scriptflow1.submit()
scriptflow2_result = scriptflow1.submit(wait_for=[scriptflow1_result ])
return scriptflow2_result
In this example, would creating a third py script be the best way to organize/build this?Colton
04/17/2024, 4:03 PMimport scriptflow1
on the main flow script?Kevin Grismore
04/17/2024, 4:07 PMKevin Grismore
04/17/2024, 4:07 PM@flow
-decorated functions just like normal python functions. they just do all the cool prefect stuff when you call themColton
04/17/2024, 4:09 PM